I have come across a problem when I am trying to extend ApplicationController with a .rb file containing a module inside /lib folder. The problem is, let''s say if I want to add a method called authenticate inside ApplicationController using ApplicationController.send(:include), I would do it as: extension.rb module Extension module ClassMethods ... end def self.included(base) base.extend(Extension.ClassMethods) end end ApplicationController.send(:include, Extension) This would work only if I put the require statement at the end of application.rb, I want to know if there is any chance it would work too if I want to put the require statement at the top? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 15 May 2008, at 08:45, goodwill wrote:> > I have come across a problem when I am trying to extend > ApplicationController with a .rb file containing a module inside /lib > folder. > > The problem is, let''s say if I want to add a method called > authenticate inside ApplicationController using > ApplicationController.send(:include), I would do it as: > > extension.rb > module Extension > module ClassMethods > ... > end > def self.included(base) > base.extend(Extension.ClassMethods) > end > end > > ApplicationController.send(:include, Extension) > > This would work only if I put the require statement at the end of > application.rb, I want to know if there is any chance it would work > too if I want to put the require statement at the top? >Have a think: if you do that you''re trying to something to application controller even though it hasn''t been defined yet. 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-/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 -~----------~----~----~----~------~----~------~--~---
Thats why its a difficult question :) I managed to fix it by extend ActionController::Base instead, I have seen plugins doing that. On May 15, 5:09 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 15 May 2008, at 08:45, goodwill wrote: > > > > > > > I have come across a problem when I am trying to extend > > ApplicationController with a .rb file containing a module inside /lib > > folder. > > > The problem is, let''s say if I want to add a method called > > authenticate inside ApplicationController using > > ApplicationController.send(:include), I would do it as: > > > extension.rb > > module Extension > > module ClassMethods > > ... > > end > > def self.included(base) > > base.extend(Extension.ClassMethods) > > end > > end > > > ApplicationController.send(:include, Extension) > > > This would work only if I put the require statement at the end of > > application.rb, I want to know if there is any chance it would work > > too if I want to put the require statement at the top? > > Have a think: if you do that you''re trying to something to application > controller even though it hasn''t been defined yet. > > 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-/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 -~----------~----~----~----~------~----~------~--~---