2011-12-18 3 views
0

RoR을 처음 접했고 다른 언어에서 선호하는 방법론 중 하나는 뚱뚱한 모델을 정의하는 것입니다. 다른 예제를 보면이 아이디어는 꽤 솔직하게 보입니다.하지만 방법론을 구현하는 데 문제가 있습니다. 레일 및 뚱뚱한 모델

는 내가 테스트를 위해 만든 아주 간단한 모델을 가지고 :
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

답변

2

클래스 메소드를 정의하고 있는데 인스턴스가 아닌 클래스 이름 앞에 접두사를 붙여 액세스하십시오.