渲染回部分内容
我有一个由 RoR 中的几个部分组成的页面。 当用户按下某个按钮时,部分内容将会出现,并且它们会在同一页面中呈现。 当我更改页面时,我希望浏览器的后退按钮不在没有渲染部分的索引页面中将我重定向到,而是在我离开之前由多个部分组成的同一页面中。
是否可以 ? 如果是的话怎么办?
I have a page composed of several partial in RoR.
The partial will appear as the user press some button, and they're rendered in the same page.
When I change the page, I want that the back button of the browser redirect me not in the index page without the partial rendered, but exactly in the same page already composed by the several partial as it was before I left.
Is it possible ?
If yes how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑设置一个会话变量或 cookie,它存储有关当前用户浏览的一些信息。
在我的应用程序中,我有几个打开扩展工具栏的开关,如果用户打开了它,我希望它对他们保持打开状态,无论他们重新加载还是返回等。
因此,这样做,当他们打开时,我有一个 AJAX 请求单击该按钮(看起来您已经要执行此操作以便在单击时呈现部分内容)。
在显示部分的控制器操作中,我将包含以下内容:
然后在您看来,您可以说:
唯一的问题是您必须确保在整个应用程序中定义了 session[:user_options] ,否则有时会出现 nil 对象错误。
我不知道这是否真的是针对您的特定问题的最佳解决方案,但这是我熟悉的解决方案。测试一下,也许您可以重新组合基本思想以满足您的需要。
You might consider setting a session variable, or a cookie, that stores a bit of information about the current user's browsing.
In my app I have a couple of toggles that open expanded toolbars, and if the user has opened it I want it to stay open for them whether they reload or go back etc.
So, do to this, I have an AJAX request when they click the button (which it looks like you're going to do already in order to render partials on a click).
In the controller action to show the partial I would include something like:
Then in your view you can say:
The only gotcha is you'll have to ensure that session[:user_options] is defined throughout your app, or else you'll sometimes get nil object errors.
I don't know if this is really the best solution for your particular problem, but it is a solution that I'm familiar with. Test it out a bit, maybe you can remix the basic idea to fit what you need.