रेल 3 में, मैं मॉडल में एक ही स्कोप बना देता हूं। उदाहरण के लिएक्या मैं रेल में मॉड्यूल के साथ सामान्य ActiveRecord scopes (स्कोप) का उपयोग कर सकता हूं?
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
मैं सामान्य स्कॉप्स को lib में मॉड्यूल में विभाजित करना चाहता हूं। तो मैं इस तरह की कोशिश करता हूँ।
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
और मैं इस एक
class Common < ActiveRecord::Base
include ScopeExtension::Timestamps
end
लिखने लेकिन रेल इस त्रुटि को दिखाते हैं।
undefined method `scope' for ScopeExtension::Timestamps::ClassMethods:Module
(मैं ऑटो लाइब्रेरी लोड करने भूल नहीं किया था) कैसे मैं आसानी से सक्रिय रिकॉर्ड में आम गुंजाइश सुविधा का पुन: उपयोग कर सकते हैं?
मुझे लगता है कि लोडिंग अनुक्रम से संबंधित यह समस्या है। लेकिन मुझे हल करने का कोई विचार नहीं है। कृपया मुझे संकेत दें।