John Kopanas
2005-Jun-01 18:04 UTC
method finishing processing even after encountering a redirect
At the beggining of one of my methods I have the following code: if session[:id] == nil session[:jump_to] = @request.parameters redirect_to :controller => "sign_up" end I expect that when if evaluates to true that the rest of the method will not be executed but it seems to be. Does that make sense?
Scott Barron
2005-Jun-01 18:07 UTC
Re: method finishing processing even after encountering a redirect
On Jun 1, 2005, at 2:04 PM, John Kopanas wrote:> At the beggining of one of my methods I have the following code: > > if session[:id] == nil > session[:jump_to] = @request.parameters > redirect_to :controller => "sign_up" > end > > I expect that when if evaluates to true that the rest of the method > will not be executed but it seems to be. Does that make sense? >redirect_to cannot explicitly return from your method, so you''ll have to do it yourself if you want to stop the processing. e.g.: def my_action if session[:id] == nil redirect_to ... return end # .... other stuff end -Scott _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Scott Barron
2005-Jun-01 18:08 UTC
Re: method finishing processing even after encountering a redirect
On Jun 1, 2005, at 2:07 PM, Scott Barron wrote:> > On Jun 1, 2005, at 2:04 PM, John Kopanas wrote: > >> At the beggining of one of my methods I have the following code: >> >> if session[:id] == nil >> session[:jump_to] = @request.parameters >> redirect_to :controller => "sign_up" >> end >> >> I expect that when if evaluates to true that the rest of the method >> will not be executed but it seems to be. Does that make sense? >> > > redirect_to cannot explicitly return from your method, so you''ll have > to do it yourself if you want to stop the processing. e.g.:(that should be "implicitly" not "explicitly") _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
John Kopanas
2005-Jun-01 18:10 UTC
Re: method finishing processing even after encountering a redirect
What if I took out the if stuff and made it into it''s own method? Could the method stop the processing and not return back to the controller method? On 1-Jun-05, at 2:07 PM, Scott Barron wrote:> > On Jun 1, 2005, at 2:04 PM, John Kopanas wrote: > > >> At the beggining of one of my methods I have the following code: >> >> if session[:id] == nil >> session[:jump_to] = @request.parameters >> redirect_to :controller => "sign_up" >> end >> >> I expect that when if evaluates to true that the rest of the >> method will not be executed but it seems to be. Does that make >> sense? >> >> > > redirect_to cannot explicitly return from your method, so you''ll > have to do it yourself if you want to stop the processing. e.g.: > > def my_action > if session[:id] == nil > redirect_to ... > return > end > # .... other stuff > end > > -Scott > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Josh Knowles
2005-Jun-01 18:19 UTC
Re: method finishing processing even after encountering a redirect
On 6/1/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:> What if I took out the if stuff and made it into it''s own method? > Could the method stop the processing and not return back to the > controller method?I think what you are looking for is a Before Filter, check out the code for the LoginGenerator (http://wiki.rubyonrails.com/rails/show/LoginGenerator) for examples.