Alexis ROBERT
2007-Dec-19 13:41 UTC
Very strange problem with application.rb and login_generator
Hi, I''m working on a very simple project, and I need to add authentification (I choose login_generator). So, i''ve added the required things in application.rb, the require_dependency and the include stuff. In the controller which requires auth, I''ve added before_filter :login_required. Exactly what they say in the documentation. The problem is that I get "undefined method `login_required'' for #<DrugsController:0x11345ec>". If I define a function named "test" in application.rb and if I call it from drugs_controller.rb, I get the same message. Tell me if I''m wrong, but the controllers normally inherits from ApplicationController defined in application.rb, no ? Why the functions are not accessible even if they are protected or public ? Btw, i''m using Rails 2.0.1. Thanks in advance Alexis ROBERT --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David A. Black
2007-Dec-19 13:47 UTC
Re: Very strange problem with application.rb and login_generator
Hi -- On Wed, 19 Dec 2007, Alexis ROBERT wrote:> > Hi, > > I''m working on a very simple project, and I need to add > authentification (I choose login_generator). So, i''ve added the > required things in application.rb, the require_dependency and the > include stuff. In the controller which requires auth, I''ve added > before_filter :login_required. Exactly what they say in the > documentation. > > The problem is that I get "undefined method `login_required'' for > #<DrugsController:0x11345ec>". > > If I define a function named "test" in application.rb and if I call it > from drugs_controller.rb, I get the same message. > > Tell me if I''m wrong, but the controllers normally inherits from > ApplicationController defined in application.rb, no ? Why the > functions are not accessible even if they are protected or public ? > > Btw, i''m using Rails 2.0.1. > > Thanks in advanceThis is just a guess, but did you put the login_required method after the ''end'' line of the controller class? If so, move it up :-) David -- Training for 2008! Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, New York, NY, February 4-7 2008 * Advancing With Rails, New York, NY, February 11-14 2008 Hosted by Exceed Education. See http://www.rubypal.com for details! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alexis ROBERT
2007-Dec-19 14:06 UTC
Re: Very strange problem with application.rb and login_generator
Hmm ... no :) That''s the code : -- drugs_controller.rb -- class DrugsController < ApplicationController layout "standard" before_filter :login_required [snip] end -- application.rb -- require_dependency "login_system" class ApplicationController < ActionController::Base include LoginSystem helper :all # include all helpers, all the time [protect_from_forgery stuff] end Alexis On 19 déc, 14:47, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > > > On Wed, 19 Dec 2007, Alexis ROBERT wrote: > > > Hi, > > > I''m working on a very simple project, and I need to add > > authentification (I choose login_generator). So, i''ve added the > > required things in application.rb, the require_dependency and the > > include stuff. In the controller which requires auth, I''ve added > > before_filter :login_required. Exactly what they say in the > > documentation. > > > The problem is that I get "undefined method `login_required'' for > > #<DrugsController:0x11345ec>". > > > If I define a function named "test" in application.rb and if I call it > > from drugs_controller.rb, I get the same message. > > > Tell me if I''m wrong, but the controllers normally inherits from > > ApplicationController defined in application.rb, no ? Why the > > functions are not accessible even if they are protected or public ? > > > Btw, i''m using Rails 2.0.1. > > > Thanks in advance > > This is just a guess, but did you put the login_required method after > the ''end'' line of the controller class? If so, move it up :-) > > David > > -- > Training for 2008! > Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: > * Intro to Rails, New York, NY, February 4-7 2008 > * Advancing With Rails, New York, NY, February 11-14 2008 > Hosted by Exceed Education. Seehttp://www.rubypal.comfor details!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg
2007-Dec-19 23:07 UTC
Re: Very strange problem with application.rb and login_generator
LoginSystem is old and possibly not maintained any more. I think it''s been superseded by AuthenticatedSystem (acts_as_authenticated) and the methods used in both modules are very similar. I recommend upgrading to acts_as_authenticated http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated On Dec 20, 2007 12:36 AM, Alexis ROBERT <alexis.robert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hmm ... no :) > > That''s the code : > > -- drugs_controller.rb -- > class DrugsController < ApplicationController > layout "standard" > before_filter :login_required > > [snip] > end > > -- application.rb -- > require_dependency "login_system" > > class ApplicationController < ActionController::Base > include LoginSystem > helper :all # include all helpers, all the time > > [protect_from_forgery stuff] > end > > Alexis > > > On 19 déc, 14:47, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote: > > Hi -- > > > > > > > > On Wed, 19 Dec 2007, Alexis ROBERT wrote: > > > > > Hi, > > > > > I''m working on a very simple project, and I need to add > > > authentification (I choose login_generator). So, i''ve added the > > > required things in application.rb, the require_dependency and the > > > include stuff. In the controller which requires auth, I''ve added > > > before_filter :login_required. Exactly what they say in the > > > documentation. > > > > > The problem is that I get "undefined method `login_required'' for > > > #<DrugsController:0x11345ec>". > > > > > If I define a function named "test" in application.rb and if I call it > > > from drugs_controller.rb, I get the same message. > > > > > Tell me if I''m wrong, but the controllers normally inherits from > > > ApplicationController defined in application.rb, no ? Why the > > > functions are not accessible even if they are protected or public ? > > > > > Btw, i''m using Rails 2.0.1. > > > > > Thanks in advance > > > > This is just a guess, but did you put the login_required method after > > the ''end'' line of the controller class? If so, move it up :-) > > > > David > > > > -- > > Training for 2008! > > Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: > > * Intro to Rails, New York, NY, February 4-7 2008 > > * Advancing With Rails, New York, NY, February 11-14 2008 > > Hosted by Exceed Education. Seehttp://www.rubypal.comfor details! > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alexis ROBERT
2007-Dec-21 17:50 UTC
Re: Very strange problem with application.rb and login_generator
Thanks a lot ! But, by the way, the main problem is still here (and so, if i want to put authentification, i need to copy/paste the include line, which is not very clean :) ) : For example, this code raises an "undefined method `blah'' for #<DrugsController:0x17d60bc>" : -- drugs_controller.rb -- class DrugsController < ApplicationController def index self.blah() end end -- application.rb -- class ApplicationController < ActionController::Base helper :all # include all helpers, all the time def blah return 2 end end If I put "print self.blah" before self.blah(), i get a "nil". So the method is not inherited (even if i put it protected). I don''t understand how can it could be (unless that the "ApplicationController" in drugs_controller.rb is not the same as the application.rb''s one, but that''s pretty weird). Alexis Le 20 déc. 07 à 00:07, Ryan Bigg a écrit :> LoginSystem is old and possibly not maintained any more. I think > it''s been superseded by AuthenticatedSystem (acts_as_authenticated) > and the methods used in both modules are very similar. I recommend > upgrading to acts_as_authenticated http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated > > On Dec 20, 2007 12:36 AM, Alexis ROBERT < alexis.robert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Hmm ... no :) > > That''s the code : > > -- drugs_controller.rb -- > class DrugsController < ApplicationController > layout "standard" > before_filter :login_required > > [snip] > end > > -- application.rb -- > require_dependency "login_system" > > class ApplicationController < ActionController::Base > include LoginSystem > helper :all # include all helpers, all the time > > [protect_from_forgery stuff] > end > > Alexis > > > On 19 déc, 14:47, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote: > > Hi -- > > > > > > > > On Wed, 19 Dec 2007, Alexis ROBERT wrote: > > > > > Hi, > > > > > I''m working on a very simple project, and I need to add > > > authentification (I choose login_generator). So, i''ve added the > > > required things in application.rb, the require_dependency and the > > > include stuff. In the controller which requires auth, I''ve added > > > before_filter :login_required. Exactly what they say in the > > > documentation. > > > > > The problem is that I get "undefined method `login_required'' for > > > #<DrugsController:0x11345ec>". > > > > > If I define a function named "test" in application.rb and if I > call it > > > from drugs_controller.rb, I get the same message. > > > > > Tell me if I''m wrong, but the controllers normally inherits from > > > ApplicationController defined in application.rb, no ? Why the > > > functions are not accessible even if they are protected or > public ? > > > > > Btw, i''m using Rails 2.0.1. > > > > > Thanks in advance > > > > This is just a guess, but did you put the login_required method > after > > the ''end'' line of the controller class? If so, move it up :-) > > > > David > > > > -- > > Training for 2008! > > Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: > > * Intro to Rails, New York, NY, February 4-7 2008 > > * Advancing With Rails, New York, NY, February 11-14 2008 > > Hosted by Exceed Education. Seehttp://www.rubypal.comfor details! > > > > > > -- > Ryan Bigg > http://www.frozenplague.net > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---