Can the \'Back\' browser functionality be invoked from a Rails \'Back\' link?
This will work similarly as browser back button try this
<%= link_to 'Back', 'javascript:history.go(-1);' %>
Use
<%= link_to 'Back', :back %>
This is specificied in the RDoc here
This generates some Javascript to navigate backward. I've just tested it, and it works.
Pay attention to this comment from the user rthbound! As he notes, link_to
with the symbol :back
does not always generate a “real” back event as if the user clicked on their browser’s Back button. It can also be a resubmit of the action that loaded the current view.
The documentation for Rails 4.2.6 says this about link_to
and the :back
symbol:
Using a
:back
Symbol instead of an options hash will generate a link to the referrer (a JavaScript back link will be used in place of a referrer if none exists).
Using
link_to_function "Back", "history.back()"
seems to be exactly like hitting the back button in the browser. All inputted form data is still there when you get back.