class SomeModel < ActiveRecord::Base
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
end
I want to extend the AR::Base class to have this named_scope for all models, how I can do this ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Create a new initializer file in config/initializers and then re-open ActiveRecord’s
Baseclass to add the named scope:—Of course you get a rather ugly error should you attempt to use this named scope on a model that doesn’t have a
created_atattribute…