somebody help me to get previous page url in RoR

hi all,
         im having a view page called "edit" and im having a back button
in it.im using this edit view page in many place of my application.i
want to go back to the page which calls this "edit" page no matter what
that page is.so somebody please help me to get the previous page url in
ruby on rails.waiting for the response.

regards,

karthik.

request.referer might be what you want ^-^

Karthikragunath Bhavani wrote:

hi all,
         im having a view page called "edit" and im having a back button
in it.im using this edit view page in many place of my application.i
want to go back to the page which calls this "edit" page no matter what
that page is.so somebody please help me to get the previous page url in
ruby on rails.waiting for the response.

regards,

karthik.

How i normally do this is to have an application.rb method which saves
the current url to the session, and another that redirects to the stored
url (which should have a default in case it can't find it). Then, in
pages which i want to bookmark for returning to (you might not want
someone to get sent back to some pages), then save the url.

EG in application.rb

  def store_location
    session['saved_location'] = request.request_uri
  end

  def redirect_to_back_or_default(default)
    if session['saved_location'].nil?
      redirect_to default
    else
      redirect_to session['return-to']
      session['saved_location'] = nil
    end
  end

Then, in a page that you want the user to be able to go back to:

<% store_location %>

Then, just call
'redirect_to_back_or_default('enter your chosen default url here,
depending on context')

to send someone back.

I think i copied this off someone else a while ago so props if this is
your code :slight_smile:

Thanks williams,

                  its working great.thanks for ur timely help.