开发者

Getting a loop when using link_to :back

I have this structure for the table course:

Search page -> Result Page -> Edit Page -> Show page

When i go from result page to a specific course edit page, i edit it, and end up on the show 开发者_如何学编程page, but when i hit back, i get a loop from show to edit, and back to show and so on.

I want the edit page to back to the result page if it came from there.

im using this on both:

<%= link_to "Back", :back %>


When you actually update your record having edited it you're likely to be doing a redirect from an update action via a put request to show. Even if you're not, and if you're defying convention and updating from the show action, you're trying to navigate to a post action with a get request. If I understand you correctly, you want to be able to edit from either the search result or the show page. What you should do is define a method that allows you to store a location in the session on demand. Put it in the application controller and it will be available to all of your controllers.

# copy this into your application_controller.rb file :
private
def store_location
  session[:return_to] = request.request_uri
end

#copy this to the top of your item_controller.rb file:
before_filter :store_location, :only => [:search, :show]

#replace your <%= link_to "Back", :back %> with
<%= link_to 'back', session[:return_to] -%>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜