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