views:

51

answers:

2

If not, is there a gem I can install that lets me do something like:

<%=h link_to "Back", previous_path %>

???

+8  A: 

Could you use the built in :back facility?

link_to "Back", :back

This will link to the referring page, or to the browser's 'back' action. See the docs.

Sam Phillips
Didn't know that was there. Handy.
Josh Pinter
A: 

:back works remarkably well for cancels and back buttons.

For redirecting them after a submission I needed to set a session variable.

I do something like this for my feedback form (which can be accessed from any page):

In my feedback controller

def new
  session[:referrer] = request.env["HTTP_REFERER"]
end

def create
  # blah blah, create actions
  redirect_to session[:referrer]
end

Can you do that with back?

/ JP

Josh Pinter
You should use :back.
Ryan Bigg
Okay, for 'back' buttons :back works great. Is there a way to use :back for redirect_to ? Let's say after a feedback has been created I want to return them to their previous page.
Josh Pinter