In rails3, I do the same areas in the model. eg
class Common < ActiveRecord::Base scope :recent , order('created_at DESC') scope :before_at , lambda{|at| where("created_at < ?" , at) } scope :after_at , lambda{|at| where("created_at > ?" , at) } end
I want to break common areas into a module in lib. So I try, like this one.
module ScopeExtension module Timestamps def self.included(base) base.send :extend, ClassMethods end module ClassMethods scope :recent , lambda{order('created_at DESC')} scope :before_at , lambda{|at| where("created_at < ?" , at) } scope :after_at , lambda{|at| where("created_at > ?" , at) } end end
and i write this
class Common < ActiveRecord::Base include ScopeExtension::Timestamps end
But Rails shows this error.
undefined method `scope' for ScopeExtension::Timestamps::ClassMethods:Module
(I did not forget the autoload of the library)
How can you easily reuse the general visibility feature in an active record?
I think this problem is related to the boot sequence. But I have no idea to decide. Please give me a hint.
neocoin
source share