Link back to page visited before form

user1738017 picture user1738017 · Apr 25, 2013 · Viewed 34.6k times · Source

I have a listing page, then a form, then a thank you page. I need to put a link on the thank you page that takes the user back to the page they were on before the form which always varies. I've tried using this:

= link_to "Back", :back

But this only takes them back to the previous page, so the form.

Answer

panicoper picture panicoper · Jul 7, 2014

Try this

<%= link_to 'Back', url_for(:back) %>
# if request.env["HTTP_REFERER"] is set to "http://www.example.com"
# => http://www.example.com

here is more details.