I am trying to do an active record find method. When I call it from the console it says method_missing. Ideas? init.rb require ''find_by_like'' ActiveRecord::Base.send(:include, CH::FIND::LIKE find_by_like.rb module CH module FIND #:nodoc: module LIKE #:nodoc: def self.included(base) base.send :extend, ClassMethods end module ClassMethods def find_by_like(col,name) query = ":all, :conditions => [''#{col} like %?%'', #{name}]" self.find(query) end end end end end -- 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 groups.google.com/group/rubyonrails-talk?hl=en.
Chris Habgood wrote:> I am trying to do an active record find method. When I call it from > the console it says method_missing.No, it probably doesn''t. Please post the exact error message.> > Ideas? > > init.rb > > require ''find_by_like'' > ActiveRecord::Base.send(:include, CH::FIND::LIKE > > find_by_like.rb > module CH > module FIND #:nodoc: > module LIKE #:nodoc:Don''t use all caps for your module names.> > def self.included(base) > base.send :extend, ClassMethods > end > > module ClassMethods > > def find_by_like(col,name) > query = ":all, :conditions => [''#{col} like %?%'', #{name}]"That should be a hash, not a string.> self.find(query) > end > end > > end > end > endBest, -- Marnen Laibow-Koser marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via 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 groups.google.com/group/rubyonrails-talk?hl=en.
undefined method `find_by_like'' On Wed, Feb 3, 2010 at 5:20 PM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Chris Habgood wrote: > > I am trying to do an active record find method. When I call it from > > the console it says method_missing. > > No, it probably doesn''t. Please post the exact error message. > > > > > Ideas? > > > > init.rb > > > > require ''find_by_like'' > > ActiveRecord::Base.send(:include, CH::FIND::LIKE > > > > find_by_like.rb > > module CH > > module FIND #:nodoc: > > module LIKE #:nodoc: > > Don''t use all caps for your module names. > > > > > def self.included(base) > > base.send :extend, ClassMethods > > end > > > > module ClassMethods > > > > def find_by_like(col,name) > > query = ":all, :conditions => [''#{col} like %?%'', #{name}]" > > That should be a hash, not a string. > > > self.find(query) > > end > > end > > > > end > > end > > end > > Best, > -- > Marnen Laibow-Koser > marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted via 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 groups.google.com/group/rubyonrails-talk?hl=en.
Why is it not recognizing the method? On Wed, Feb 3, 2010 at 5:43 PM, Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> undefined method `find_by_like'' > > > On Wed, Feb 3, 2010 at 5:20 PM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> Chris Habgood wrote: >> > I am trying to do an active record find method. When I call it from >> > the console it says method_missing. >> >> No, it probably doesn''t. Please post the exact error message. >> >> > >> > Ideas? >> > >> > init.rb >> > >> > require ''find_by_like'' >> > ActiveRecord::Base.send(:include, CH::FIND::LIKE >> > >> > find_by_like.rb >> > module CH >> > module FIND #:nodoc: >> > module LIKE #:nodoc: >> >> Don''t use all caps for your module names. >> >> > >> > def self.included(base) >> > base.send :extend, ClassMethods >> > end >> > >> > module ClassMethods >> > >> > def find_by_like(col,name) >> > query = ":all, :conditions => [''#{col} like %?%'', #{name}]" >> >> That should be a hash, not a string. >> >> > self.find(query) >> > end >> > end >> > >> > end >> > end >> > end >> >> Best, >> -- >> Marnen Laibow-Koser >> marnen.org >> marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org >> -- >> Posted via 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- 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 groups.google.com/group/rubyonrails-talk?hl=en.