Rails named_scope as an extension to AR :: Base
1 answer
Create a new initialization file in config / initializers and then run the ActiveRecord class again Base
to add the named scope:
module ActiveRecord
class Base
named_scope :recent, lambda {
{ :conditions => ['created_at > ?', 1.week.ago] }
}
end
end
& mdash. Of course, you get a rather ugly error if you try to use this named scope on a model that has no attribute created_at
...
+3
a source to share