Session[:return_to] for going back

Hi,

Is session[:return_to] something Rails maintains to quickly go back to
the
previous uri without having to keep track of the action name? Or, do we
have to actually set it in our actions?

Thanks.

I am not sure if this is applicable for you but I use the following exta
‘link’ functions:

#links back to page where it came with back_name
def link_back(back_name, html_options = nil,
*parameters_for_method_reference)
request.referer or return ‘’
if html_options
html_options = html_options.stringify_keys
convert_options_to_javascript!(html_options)
tag_options = tag_options(html_options)
else
tag_options = nil
end
“<a href=”#{request.referer}"#{tag_options}>#{back_name ||
request.referer}"
end

#links back to page where it came with back_name; otherwise falls back
to link_to
def link_back_or_to(back_name, name, options = {}, html_options = nil,
*parameters_for_method_reference)
ret = link_back(back_name, html_options,
parameters_for_method_reference)
return ret if !ret.empty?
link_to(name, options, html_options,
parameters_for_method_reference)
end

for redirection you can use redirect_to :back

Not sure if this is what you are after.

Cheers,
Anton

On May 10, 2006, at 12:17 AM, Sam D. wrote:

Is session[:return_to] something Rails maintains to quickly go back
to the previous uri without having to keep track of the action
name? Or, do we have to actually set it in our actions?

(Assuming you’re referring to the earlier url_back code sample.)

You must set it yourself. Rails can’t tell which page you wish to
return to or when such a setting is appropriate.

I like embedding return_to in form parameters because the user can
work with multiple tabs/windows without having one tab return to the
other’s :return_to.

Best,
jeremy