Forum: Ruby on Rails Return to previous page

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Juan K. (Guest)
on 2009-04-15 19:18
Is there a 'rails way' to allow easy navigation to the previous page or
should we use parameters and 'ifs'?
I'm talking about, for example, a 'Back' button that links to differente
pages depending the previous page.
Thanks.
David K. (Guest)
on 2009-04-15 23:15
(Received via mailing list)
On 15 Apr., 17:18, Juan K. <removed_email_address@domain.invalid>
wrote:
> Is there a 'rails way' to allow easy navigation to the previous page or
> should we use parameters and 'ifs'?
> I'm talking about, for example, a 'Back' button that links to differente
> pages depending the previous page.

You can easily make a back button like this:

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

button_to will pass the second argument (:back) on to url_for, and as
you can see in the documentation (http://api.rubyonrails.org/classes/
ActionView/Helpers/UrlHelper.html#M001564), :back will be translated
to request.env["HTTP_REFERER"] or javascript:history.back() if referer
is blank. That's it!

--
Best regards,
David K.
http://twitter.com/rubyguy
This topic is locked and can not be replied to.