Hi There,
I have several ajax elements that require authorization, but for various
reasons, they can''t pass session[original_uri] to the redirect on user
log in. I''m trying to hack in a uri by passing a param to the login
page.
I can see that the param is passing into the login page, but for
whatever reason, no matter what I do, the user is redirected to the
homepage after login.
Would anyone have any ideas? thanks soo much!
-Mario
#code from show.rhtml
if current_user
#ajax code
else
link_to "vote up", login_url(:referrer_uri =>
request.request_uri) %>
end
#Controller
def create
uri ||= params[:referrer_uri] #pull in hacked original_uri
uri ||= session[:original_uri] #pull in sessions''s original uri
uri ||= homepage_url #default to homepage
render :action => :new and return true if request.get?
if params[:user_name] and params[:password] and user
User.authenticate(params[:user_name], params[:password])
session[:user_id] = user.id
session[:original_uri] = nil
redirect_to(uri) and return true
else
flash[:failure] = "Invalid username or password."
redirect_to login_url and return false
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
No Luck, hu? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Muller
2007-Nov-14 09:53 UTC
Re: Login Redirect - Hacking the session[original_uri]
i''ve used that thing several times, as you want it and it works fine.
seems to me, it didn''t reach the redirect_to(uri) line for some reason
or uri is not set to the right path in the first lines of your action
check it that way:
add
logger.info "URI: #{uri}"
behind those "uri ||=" lines
and something the like before your redirects. then check in
development.log, what actually is in those vars and which parts of your
code are reached.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks for the tip! That helped me track down my problem. Apparently, the uri wasn''t getting carried over the the create action in my session controller. So I just added the param to my login form. <% form_tag login_path(:referrer_uri => params[:referrer_uri]), :class => "submit-form login" do %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Muller
2007-Nov-14 16:10 UTC
Re: Login Redirect - Hacking the session[original_uri]
Mario Flores wrote:> Thanks for the tip! > > That helped me track down my problem. Apparently, the uri wasn''t > getting carried over the the create action in my session controller. So > I just added the param to my login form. > > > <% form_tag login_path(:referrer_uri => params[:referrer_uri]), :class > => "submit-form login" do %>lo, you didn''t mention a form, in that case te user had to press the ''submit'' and your link_to is dead anyway (? i think) :) your solution is ok, alternately you could pass stuff like that in a hidden field not, that there''s a big difference -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---