ruby on rails - Link back to page visited before form -
i have listing page, form, thank page. need put link on thank page takes user page on before form varies. i've tried using this:
= link_to "back", :back
but takes them previous page, form.
well, can set method in form page collect url. basic idea use custom session variable store previous url , keep next session.
suppose form's action somecontroller#new, then
class somecontroller < applicationcontroller after_filter "save_my_previous_url", only: [:new] def save_my_previous_url # session[:previous_url] rails built-in variable save last url. session[:my_previous_url] = uri(request.referer || '').path end end
then in thank page, can my_previous_url
by
session[:my_previous_url]
this should able suit case, previous url 2 pages ago.
disclaimer: not verified. idea only.
add
session belongs controller. not helper can use directly in view. need define instance variable in controller , can use in view. this
# controller @back_url = session[:my_previous_url] # view <%= link_to "back", @back_url %>