Hi,
I have extended the ActiveRecord::Base class as follows:
lib/activerecord_ext.rb:
class ActiveRecord::Base
named_scope(
:recent,
:conditions => ['created_at > ?', (Time.new - 3.day)],
:order => 'created_at DESC',
:limit => 5
)
end
In config/environment.rb:
require "activerecord_ext"
This works fine until class caching is enabled. When I set
config.cache_classes = true
I get this error:
>> 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
I assume I'm doing something wrong with the inclusion of the extension. Any help would be greatly appreciated.