Forum: Ruby on Rails session[:return_to] for going back.

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.
036be8d5d83a98e546b98d64e3fd6c20?d=identicon&s=25 Sam Donaldson (Guest)
on 2006-05-10 09:20
(Received via mailing list)
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.
03a3c76fd9d39f8b2e3b04733843726c?d=identicon&s=25 Anton Koukine (antonk)
on 2006-05-10 12:25
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}</a>"
  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
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2006-05-10 18:24
(Received via mailing list)
On May 10, 2006, at 12:17 AM, Sam Donaldson 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
This topic is locked and can not be replied to.