Working on an ActiveRecord plugin. It''s a bit of a complex thing in
which in an instance method, the domain logic requires a search on
the table.
In the code below, the find in do_object_stuff gripes with an
undefined method error.
self.find, parent.find, super.find, and just find don''t work -- while
most of those errors make sense to me, I am surprised that a plain
find doesn''t work. It''s just a class method,
shouldn''t an instance be
able to just use that?
Weak brain moment... I can''t see what I am missing. Not sure if the
plugin context is relevant or not.
module BlahBlahBlah
def self.included(base)
.... etc....
module ActMethods
.... etc....
module ClassMethods
def do_class_stuff(parameters)
.....
record = find(:key_value, :select => select_fields)
.....
end
end
module InstanceMethods
def do_object_stuff(parameters)
.....
record = find(:key_value, :select => select_fields)
.....
end
end
end
-- gw
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-03 23:02 UTC
Re: AR Plugin class method calls from instance methods
On Jun 3, 9:23 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> Working on an ActiveRecord plugin. It''s a bit of a complex thing in > which in an instance method, the domain logic requires a search on > the table. > > In the code below, the find in do_object_stuff gripes with an > undefined method error. > > self.find, parent.find, super.find, and just find don''t work -- while > most of those errors make sense to me, I am surprised that a plain > find doesn''t work. It''s just a class method, shouldn''t an instance be > able to just use that? >self.class.find Class methods in rails are just singleton methods on the appropriate object. find is the same thing as self.find (when there is no receiver the self is implicit) so it''s not surprising that it doesn''t work 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 -~----------~----~----~----~------~----~------~--~---
On Jun 3, 2008, at 4:02 PM, Frederick Cheung wrote:> On Jun 3, 9:23 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: >> Working on an ActiveRecord plugin. It''s a bit of a complex thing in >> which in an instance method, the domain logic requires a search on >> the table. >> >> In the code below, the find in do_object_stuff gripes with an >> undefined method error. >> >> self.find, parent.find, super.find, and just find don''t work -- while >> most of those errors make sense to me, I am surprised that a plain >> find doesn''t work. It''s just a class method, shouldn''t an instance be >> able to just use that? >>> self.class.findAha. Makes sense. Muchas grass... -- gw --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---