[Rails] "Remembering" link to redirect to after logging in
Francesc Esplugas
francesc.esplugas at gmail.com
Tue Mar 21 10:50:57 GMT 2006
For doing this I usually use a session[]. The user tries to login, and if
it's not authenticated the authentication method stores the
"intended_controller" in a session[]. Then when the user logs in the
system the login method redirects to the previously intended controller.
Hope that helps,
Francesc
-------------------------------------------------------
##########################################
# The Admin controller
##########################################
before_filter :authentication
def authentication
unless session[:user]
session[:intended_controller] = '/admin/' + controller_name
redirect_to :controller => '/account'
end
end
#########################################
# The account controller
#########################################
def login
# Here comes the login code ...
if # login is successful ...
redirect_to session[:current_page]
else
redirect_to '/account/login'
end
----------------------------------------------------------
--
name. Francesc Esplugas
email. francesc.esplugas at gmail.com
On Tue, 21 Mar 2006, Woei Shyang wrote:
> Date: Tue, 21 Mar 2006 11:36:01 +0100
> From: Woei Shyang <woeishyang at gmail.com>
> Reply-To: rails at lists.rubyonrails.org
> To: rails at lists.rubyonrails.org
> Subject: [Rails] "Remembering" link to redirect to after logging in
>
> Hi,
>
> Suppose I have a resource such as http://localhost:3000/topsecret/data
> that requires the user to login first.
>
> What I did was make use of before_filter to check and see if the session
> variable is set with the logged in user's id (similar to the example in
> "Agile Web Development with Rails").
>
> However while the filtering function does work correctly in redirecting
> the user to the login page, how do I actually capture the original
> request made by the user so that I can redirect the user back to the
> required resource after s/he has logged in?
>
> Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
More information about the Rails
mailing list