开发者

user.find(1) results in an exception, is my system ok or my setup is messed up?

My database is empty, and I understand that I should get an exception.

Just want to make sure that my macbookpro is setup with rails properly.

typing:

user.find(1)

in console I get:

>> user.find(1)
NoMethodError: unde开发者_开发百科fined method `find' for #<User:0x1016403a0>
    from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.0/lib/active_model/attribute_methods.rb:364:in `method_missing'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/attribute_methods.rb:46:in `method_missing'
    from (irb):25
>> 

I am using rails 3.0, with ruby 1.8.7


According to the message user is an instance of the User class. Since there is no instance method find for AR objects (unless you defined it yourself), it's perfectly normal that you get a NoMethodError.

You probably intended to call User.find(1) (capital U).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜