我是RoR的新手,我更喜歡其他語言的一種方法是定義胖模型的能力。看看其他例子,這個想法看起來非常簡單,但是我在實施這個方法時遇到了一些問題。Rails and Fat Models
我有我爲測試創造了一個非常簡單的模型:
class Account::User < ActiveRecord::Base
#validates_presense_of :username, :first_name, :last_name, :instance_id, :user_type, :is_active
#validates_uniqueness_of :username
def self.all_by_user_type(user_type)
p user_type
end
end
當我嘗試使用方法all_by_user_type我得到下面的異常。任何幫助,這是非常感謝。
irb(main):002:0> u.all_by_user_type(1) NoMethodError: undefined method
all_by_user_type' for #<Account::User:0x7ffe60baebe8> from /usr/lib/ruby/gems/1.8/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in
method_missing' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.3/lib/active_record/attribute_methods.rb:60:in `method_missing' from (irb):2 from :0