[Rails] Re: session[:return_to] for going back.

anton koukine
Wed, 10 May 2006 10:25:47 -0000

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

--
Posted via http://www.ruby-forum.com/.