Chris Hall
2006-Aug-17 13:16 UTC
[Rails] find method not interpreting arguments correctly?
i''ve got a situtation where i''m trying to pass arguments from a method to find and AR is telling me that it can''t find the record where id=all here''s what i am attempting to do class Thing < ActiveRecord::Base belongs_to :x end class FlyingThing < Thing end class x < ActiveRecord::Base has_many :things do def that_fly(*args) FlyingThing.find(args) end end end so if i were to do x.find(:first).things.that_fly(:all) i get ActiveRecord::RecordNotFound: Couldn''t find FlyingThing with ID=all is this a bug or am i doing something wrong? Chris
Chris Hall
2006-Aug-18 12:27 UTC
[Rails] Re: find method not interpreting arguments correctly?
anyone got any ideas on this? On 8/17/06, Chris Hall <christopher.k.hall@gmail.com> wrote:> i''ve got a situtation where i''m trying to pass arguments from a method > to find and AR is telling me that it can''t find the record where > id=all > > here''s what i am attempting to do > > class Thing < ActiveRecord::Base > belongs_to :x > end > > class FlyingThing < Thing > end > > class x < ActiveRecord::Base > has_many :things do > def that_fly(*args) > FlyingThing.find(args) > end > end > end > > so if i were to do > > x.find(:first).things.that_fly(:all) > > i get > > ActiveRecord::RecordNotFound: Couldn''t find FlyingThing with ID=all > > > is this a bug or am i doing something wrong? > > Chris >
Ezra Zygmuntowicz
2006-Aug-18 18:24 UTC
[Rails] Re: find method not interpreting arguments correctly?
On Aug 18, 2006, at 5:27 AM, Chris Hall wrote:> anyone got any ideas on this?You need to splat the args into the find command. Try this: class x < ActiveRecord::Base has_many :things do def that_fly(*args) FlyingThing.find(*args) end end end -Ezra