0
我已經擴展了的ActiveRecord :: Base類如下:滑軌:緩存類忽略混入
LIB/activerecord_ext.rb:
class ActiveRecord::Base
named_scope(
:recent,
:conditions => ['created_at > ?', (Time.new - 3.day)],
:order => 'created_at DESC',
:limit => 5
)
end
在配置/ environment.rb中:
require "activerecord_ext"
這可以正常工作,直到啓用類緩存。當我設置
config.cache_classes = true
我得到這個錯誤:
>> Person.recent
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.call
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/named_scope.rb:102:in `recent'
from (irb):1
我認爲我做錯了一起列入延長。任何幫助將不勝感激。
這樣做,謝謝。 – Thilo 2009-09-16 17:30:28