I''m trying to add a mixin i wrote (ModelExtensions module in lib/model_extensions.rb) to ActiveRecord::Base so that i can use the methods in it in all my classes. (well actually there''s only a single method in there at the moment) I''ve added this to environment.rb (right at the bottom): require ''model_extensions'' ActiveRecord::Base.send(:extend, ModelExtensions) And the web server starts ok. But the mixin just doesn''t seem to work - I get a "missing method" message. So, i explicitly added the mixin to the required classes, with require ''model_extensions'' at the top of the model file. Still no joy. Modules in lib should work shouldn''t they? Can anyone see what i''m doing wrong? thanks in advance -- 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-/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 7/31/07, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m trying to add a mixin i wrote (ModelExtensions module in > lib/model_extensions.rb) to ActiveRecord::Base so that i can use the > methods in it in all my classes. (well actually there''s only a single > method in there at the moment) > > I''ve added this to environment.rb (right at the bottom): > > require ''model_extensions'' > ActiveRecord::Base.send(:extend, ModelExtensions)Is the method supposed to be a class method or an instance method? If it''s supposed to be and instance method, try include instead of extend: ActiveRecord::Base.send(:include, ModelExtensions)> > And the web server starts ok. But the mixin just doesn''t seem to work - > I get a "missing method" message. > > So, i explicitly added the mixin to the required classes, with > > require ''model_extensions'' > > at the top of the model file. Still no joy. Modules in lib should work > shouldn''t they? Can anyone see what i''m doing wrong? > > thanks in advance > -- > 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-/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 Chelimsky wrote:> Is the method supposed to be a class method or an instance method? If > it''s supposed to be and instance method, try include instead of > extend: > > ActiveRecord::Base.send(:include, ModelExtensions)That''s fixed it! Thanks very much - i didn''t appreciate the subtleties when i blindly copied someone''s example code (a recurring problem for me with learning rails actually). cheers! -- 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-/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 8/1/07, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > David Chelimsky wrote: > > > Is the method supposed to be a class method or an instance method? If > > it''s supposed to be and instance method, try include instead of > > extend: > > > > ActiveRecord::Base.send(:include, ModelExtensions) > > That''s fixed it! Thanks very much - i didn''t appreciate the subtleties > when i blindly copied someone''s example code (a recurring problem for me > with learning rails actually). > > cheers!Cool - glad to help. Good luck! David> -- > 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-/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 -~----------~----~----~----~------~----~------~--~---