开发者

Render back a partial

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 开发者_如何学Gorendered, but exactly in the same page already composed by the several partial as it was before I left.

Is it possible ? If yes how ?


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:

...
session[:user_options][:partial_name] = true
...

Then in your view you can say:

- if session[:user_options][:partial_name] = true
  = render 'partial'

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜