Hi everyone, i followed colins example and it worked perfectly but now i get this error ActionController::DoubleRenderError in UserController#login Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". I feel that something is wrong with this code def login @title = "Login - Books" if request.post? @user = User.new(params[:user]) user = User.find_by_screen_name_and_password(@user.screen_name, @user.password) if user session[:user_id] = user.id flash[:notice] = "User #{user.screen_name} logged in" redirect_to :action => "index" else # Don''t show the password in the view @user.password = nil flash[:notice] = "Invalid email/password combination" end end if session[:user_id] flash[:notice] = "Already registed and logged in! You cannot view the register or login!" redirect_to :action => :index end end /////////////////////////////////////////////////////// if session[:user_id] flash[:notice] = "Already registed and logged in! You cannot view the register or login!" redirect_to :action => :index end /////////////////////////////////////////////////////// what this does, is if session ID is found, then it takes the login page back to index...can someone help me please :( -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 21, 7:00 pm, Tiger Big one <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi everyone, i followed colins example and it worked perfectly but now i > get this error > > ActionController::DoubleRenderError in UserController#login > > Render and/or redirect were called multiple times in this action. Please > note that you may only call render OR redirect, and at most once per > action. Also note that neither redirect nor render terminate execution > of the action, so if you want to exit an action after redirecting, you > need to do something like "redirect_to(...) and return". >In the case where the request is a post request and if the user is logged in successfully you are calling redirect_to :action => ''index'' twice Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Mar 21, 7:00�pm, Tiger Big one <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > In the case where the request is a post request and if the user is > logged in successfully you are calling redirect_to :action => ''index'' > twice > > FredI wrote the same code (exactly the same code)...twice for def login and def register. Does that matter? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 March 2010 19:21, Tiger Big one <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: >> On Mar 21, 7:00�pm, Tiger Big one <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >> In the case where the request is a post request and if the user is >> logged in successfully you are calling redirect_to :action => ''index'' >> twice >> >> Fred > > I wrote the same code (exactly the same code)...twice for def login and > def register. > > Does that matter?The answer is obvious, if it is exactly the same and you hit the right path through the code then it will fail, so yes it does matter. The reason there is a problem is that, rather non-intuitively, redirect_to is not a jump but a call, therefore execution returns after the redirect_to. You must make sure there is not another redirect. The safest thing is to put a return after redirect_to if it is in the middle of the action rather than the end. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.