I am new to RoR and one methodology I prefer in other languages is the ability to define a fat model. Looking at other examples, the idea seems pretty straight forward, but I am having a bit of an issue with implementing the methodology.
I have a very simple model that I have created for testing:
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
When I attempt to use the method all_by_user_type I get the exception below. Any help with this is greatly appreciated.
irb(main):002:0> u.all_by_user_type(1)
NoMethodError: undefined methodall_by_user_type' for #<Account::User:0x7ffe60baebe8>method_missing’
from /usr/lib/ruby/gems/1.8/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in
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
You’re defining a class method, access it by prefixing it with the class name, not an instance.