From: dblack@... Date: 2007-01-18T03:49:32+09:00 Subject: Re: ActiveRecord find_by_*() - how does it work? Hi -- On Thu, 18 Jan 2007, Eduardo Scoz wrote: > Hi guys! > > I've been trying to understand how the find_by_*() method on > ActiveRecord works, but couldn't find anything that could help. I think > that you guys can probably help me on that. > > On Active Record, you can make a call like > user.find_by_first_name_and_last_name("eduardo"...) > and this will generate the sql to send to the database. > > But how does that method gets created? ActiveRecord doesn't know what I > want to find until I actually make the call, and the number of different > combinations of parameters would probably be infinite for it to be > created during the object initialization, so (I imagine) the method must > be created __AFTER__ it was called. > > So my question is, is it possible for an object to receive a call to a > method that doesn't exist, not throw a NoMethodError, and respond to > that call? Let me be the first of probably 10 or 15 people to say: method_missing :-) David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)