Hi, Some controller filters: before_filter :require_logged_in, :only => [:create, :new, :confirm] before_filter :init_players, :only => [:create, :new, :confirm] The first one, you guessed it, redirects a user if he''s not logged in. Now when I hit this page and I''m not logged in, the 2nd filter gets executed and throws an error, because it depends on the user being logged in. I don''t really want to do an extra check in the init_players method, it''s not very DRY.. Any ideas? Jeroen
You probably need to add a return at the end of your redirect: redirect(....) and return -Larry On 11/16/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote:> > Hi, > > Some controller filters: > > before_filter :require_logged_in, :only => [:create, :new, :confirm] > before_filter :init_players, :only => [:create, :new, :confirm] > > The first one, you guessed it, redirects a user if he''s not logged in. > > Now when I hit this page and I''m not logged in, the 2nd filter gets > executed and throws an error, because it depends on the user being > logged in. I don''t really want to do an extra check in the init_players > method, it''s not very DRY.. > > Any ideas? > > Jeroen > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi ! 2005/11/16, Jeroen Houben <jeroen@terena.nl>:> Now when I hit this page and I'm not logged in, the 2nd filter gets > executed and throws an error, because it depends on the user being > logged in. I don't really want to do an extra check in the init_players > method, it's not very DRY..When you redirect, do you prevent further filter chain execution by returning false ? You would do it this way: def require_logged_in # check authentication # user not authenticated, we need to redirect redirect_to :login_url return false # prevents further filter chain execution (aborts request) end Hope that helps ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Francois Beausoleil wrote:> Hi ! > > 2005/11/16, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org>: > >>Now when I hit this page and I''m not logged in, the 2nd filter gets >>executed and throws an error, because it depends on the user being >>logged in. I don''t really want to do an extra check in the init_players >>method, it''s not very DRY.. > > > When you redirect, do you prevent further filter chain execution by > returning false ? > > You would do it this way: > def require_logged_in > # check authentication > # user not authenticated, we need to redirect > redirect_to :login_url > return false # prevents further filter chain execution (aborts request) > end > > Hope that helps !It helps! Jeroen