I created a module MyModule "my_module.rb" and put in a lib folder in my rails app. In my User.rb model I call include MyModule. When I try to use a method inside MyModule I get an "undefined method error". How do I include this module in the model? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
badnaam wrote:> I created a module MyModule "my_module.rb" and put in a lib folder in > my rails app. > > In my User.rb model I call include MyModule. > > When I try to use a method inside MyModule I get an "undefined method > error". How do I include this module in the model?What you described should work. Let''s see code.> > ThanksBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Here is the code.. http://pastie.org/1110631 Thanks On Aug 23, 12:15 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> badnaam wrote: > > I created a module MyModule "my_module.rb" and put in a lib folder in > > my rails app. > > > In my User.rb model I call include MyModule. > > > When I try to use a method inside MyModule I get an "undefined method > > error". How do I include this module in the model? > > What you described should work. Let''s see code. > > > > > Thanks > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > Sent from my iPhone > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
http://pastie.org/1110631 On Aug 23, 12:15 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> badnaam wrote: > > I created a module MyModule "my_module.rb" and put in a lib folder in > > my rails app. > > > In my User.rb model I call include MyModule. > > > When I try to use a method inside MyModule I get an "undefined method > > error". How do I include this module in the model? > > What you described should work. Let''s see code. > > > > > Thanks > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > Sent from my iPhone > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I suspect that after you require validation_group.rb you want to have
something like:
ActiveRecord::Base.class_eval { extend
ValidationGroup::ActiveRecord::ActsMethod }
You need to get the "validation_group" method into ActiveRecord::Base
and therefore User before you call it.
-Rob
On Aug 23, 2010, at 3:22 PM, badnaam wrote:
> http://pastie.org/1110631
>
> On Aug 23, 12:15 pm, Marnen Laibow-Koser
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
>> badnaam wrote:
>>> I created a module MyModule "my_module.rb" and put in a
lib
>>> folder in
>>> my rails app.
>>
>>> In my User.rb model I call include MyModule.
>>
>>> When I try to use a method inside MyModule I get an "undefined
>>> method
>>> error". How do I include this module in the model?
>>
>> What you described should work. Let''s see code.
>>
>>
>>
>>> Thanks
>>
>> Best,
>> --
>> Marnen Laibow-Koserhttp://www.marnen.org
>> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org
>>
>> Sent from my iPhone
>>
>> --
>> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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
> .
>
Rob Biedenharn
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
http://AgileConsultingLLC.com/
rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org
http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Rob,
Are you saying I need to do a
1 - require ''validation_group'' in my User.rb
2 - Then add
ActiveRecord::Base.class_eval { extend
ValidationGroup::ActiveRecord::ActsMethod }
to my User.rb?
Thanks
On Aug 23, 12:44 pm, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
wrote:> I suspect that after you require validation_group.rb you want to have
> something like:
>
> ActiveRecord::Base.class_eval { extend
> ValidationGroup::ActiveRecord::ActsMethod }
>
> You need to get the "validation_group" method into
ActiveRecord::Base
> and therefore User before you call it.
>
> -Rob
>
> On Aug 23, 2010, at 3:22 PM, badnaam wrote:
>
>
>
> >http://pastie.org/1110631
>
> > On Aug 23, 12:15 pm, Marnen Laibow-Koser
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
> >> badnaam wrote:
> >>> I created a module MyModule "my_module.rb" and put
in a lib
> >>> folder in
> >>> my rails app.
>
> >>> In my User.rb model I call include MyModule.
>
> >>> When I try to use a method inside MyModule I get an
"undefined
> >>> method
> >>> error". How do I include this module in the model?
>
> >> What you described should work. Let''s see code.
>
> >>> Thanks
>
> >> Best,
> >> --
> >> Marnen Laibow-Koserhttp://www.marnen.org
> >> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org
>
> >> Sent from my iPhone
>
> >> --
> >> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > .
> > For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en
> > .
>
> Rob Biedenharn
> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
http://AgileConsultingLLC.com/
> r...-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org
http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On Aug 23, 2010, at 3:50 PM, badnaam wrote:> On Aug 23, 12:44 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> I suspect that after you require validation_group.rb you want to have >> something like: >> >> ActiveRecord::Base.class_eval { extend >> ValidationGroup::ActiveRecord::ActsMethod } >> >> You need to get the "validation_group" method into ActiveRecord::Base >> and therefore User before you call it. >> >> -Rob > > Rob, > > Are you saying I need to do a > > 1 - require ''validation_group'' in my User.rb > > 2 - Then add > > ActiveRecord::Base.class_eval { extend > ValidationGroup::ActiveRecord::ActsMethod } > to my User.rb? > > ThanksNo, I don''t know what you "need" only what I "suspect" your code is missing. Probably not in your user.rb, but in an initializer somewhere. (config/initializers/validation_group.rb or in config/ environment.rb) If you''re modifying the plugin, you really need to understand the Ruby hook methods (like extended() and included()) or at least copy all the relevant bits when you''re cargo-culting a solution. -Rob>> >> On Aug 23, 2010, at 3:22 PM, badnaam wrote: >> >> >> >>> http://pastie.org/1110631 >> >>> On Aug 23, 12:15 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >>> wrote: >>>> badnaam wrote: >>>>> I created a module MyModule "my_module.rb" and put in a lib >>>>> folder in >>>>> my rails app. >> >>>>> In my User.rb model I call include MyModule. >> >>>>> When I try to use a method inside MyModule I get an "undefined >>>>> method >>>>> error". How do I include this module in the model? >> >>>> What you described should work. Let''s see code. >> >>>>> Thanks >> >>>> Best, >>>> -- >>>> Marnen Laibow-Koserhttp://www.marnen.org >>>> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org >> >>>> Sent from my iPhone >> >>>> -- >>>> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>> . >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en >>> . >> >> Rob Biedenharn >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ >> r...-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > . >Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ouch. Cargo cult. a bit harsh. At some point we were all learning to program. How we treat the newcomer says a lot about the Rails community. badnamm, I think what you''re trying to do might be satisfied by extend not include. see this article for more info. http://railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/ dave On Aug 23, 12:58 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Aug 23, 2010, at 3:50 PM, badnaam wrote: > > > > > > > > > > > On Aug 23, 12:44 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > >> I suspect that after you require validation_group.rb you want to have > >> something like: > > >> ActiveRecord::Base.class_eval { extend > >> ValidationGroup::ActiveRecord::ActsMethod } > > >> You need to get the "validation_group" method into ActiveRecord::Base > >> and therefore User before you call it. > > >> -Rob > > > Rob, > > > Are you saying I need to do a > > > 1 - require ''validation_group'' in my User.rb > > > 2 - Then add > > > ActiveRecord::Base.class_eval { extend > > ValidationGroup::ActiveRecord::ActsMethod } > > to my User.rb? > > > Thanks > > No, I don''t know what you "need" only what I "suspect" your code is > missing. Probably not in your user.rb, but in an initializer > somewhere. (config/initializers/validation_group.rb or in config/ > environment.rb) If you''re modifying the plugin, you really need to > understand the Ruby hook methods (like extended() and included()) or > at least copy all the relevant bits when you''re cargo-culting a > solution. > > -Rob > > > > > > > > > > > > >> On Aug 23, 2010, at 3:22 PM, badnaam wrote: > > >>>http://pastie.org/1110631 > > >>> On Aug 23, 12:15 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > >>> wrote: > >>>> badnaam wrote: > >>>>> I created a module MyModule "my_module.rb" and put in a lib > >>>>> folder in > >>>>> my rails app. > > >>>>> In my User.rb model I call include MyModule. > > >>>>> When I try to use a method inside MyModule I get an "undefined > >>>>> method > >>>>> error". How do I include this module in the model? > > >>>> What you described should work. Let''s see code. > > >>>>> Thanks > > >>>> Best, > >>>> -- > >>>> Marnen Laibow-Koserhttp://www.marnen.org > >>>> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > >>>> Sent from my iPhone > > >>>> -- > >>>> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > >>> . > >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > >>> . > > >> Rob Biedenharn > >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ > >> r...-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > . > > Rob Biedenharn > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ > r...-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.