Storing URL locations

I have a friendship system where users can create new friendships from
different views. The idea is to redirect them to where they initially
requested, accepted, etc… the friendship. To do this, I need to
store the URL path from where they are sending the request. Is there a
way to save the initial URL (from where the request mas made to the
friendships controller). Any light on this?

Thanks for your time,

Elías

I use the following code to redirect them to the page they requested
before
they logged in. Maybe this will get you on the right path. I put it in
the
controller under protected.

Protect a page from unauthorized access.

def protect
unless logged_in?
session[:protected_page] = request.request_uri
flash[:notice] = “Please log in first”
redirect_to :action => “login”
return false
end
end

Redirect to the previously requested URL (if present).

def redirect_to_forwarding_url
if (redirect_url = session[:protected_page])
session[:protected_page] = nil
redirect_to redirect_url
else
redirect_to :action => “index”
end
end

Sean McGilvray & Sarena Byers
Executive Director
Identity Theft Specialist
Pre-Paid Legal Service’s, Inc. NYSE:PPD
Phone: 760-486-1019
[email protected]
http://www.transferhome.net

Hi Sean thanks for the response.

I thought about a solution based on your answer, but I am not happy
with it. My solution consisted on having a before_filter on the
controllers I know there might be a call to the friendships
controller. This before_filter will be used to save the URL. And then,
have a before_filter on the application controller where I do this:

if params[:controller] != “friendships”
session[:return_to] = nil
end

The thing is that having this before_filter every time for every
controller doesn’t seems right.

Thanks,

Elías