I am a newby with RoR,
Environment : Rails 3.09 and ruby 1.9.2p290 installed on leopard
I am following carefully the tutorial of Michael hartl (http://ruby.railstutorial.org/). At the chapter 7, with the console we should test this code :
$ rails console --sandbox
>> User.create!(:nom => "Michael Hartl", :email => "mhartl@example.com",
?> :password => "foobar", :password_confirmation => "foobar")
>> user = User.find_by_email("mhartl@example.com")
>> user.has_password?("foobar")
=> true
My problem is with the use of the attribute based finders , find_by_(the name of the attribute). In my example find_by_email.
Actually, rails doesn't seem to accept find_by_ as a method. Still with the example above, at the line user.has_password?("foobar") rails returns the error : NoMethodError: undefined method. The method has_password? is well defined in my model.
I have checked the doc of the api of rails 3.0.9, and if I use this way :
>> user = User.where(:email => "mhartl@example.com")
then it works....
So I am wondering why I can't use the method find_by_ ? Other find methods work ex: find.first, find.last, etc..
Thank you to help me
fabien