Hi Railers.
I am trying to add very simple caching system for ActiveRecord to my
application and I need advice from Ruby (or RoR) guru.
Everything that I need is redefine find method for some of my models. I
am
trying to do with folowing code
class ActiveRecord::Base
def self.cacheable
class_eval <<-end_eval
alias old__find find
def self.find(*args)
puts "We are in find"
end
end_eval
end
end
Then I adding cacheable to my model. But when I run test I have
following
error
C:/work/agora/agora/config/…/lib/model_cachable.rb:3:in module_eval': (eval):2:in
module_eval’: undefined method find' for class
Category’
(NameError)
from C:/work/agora/agora/config/…/lib/model_cachable.rb:3:in
module_eval' from C:/work/agora/agora/config/../lib/model_cachable.rb:3:in
cacheable’
from C:/work/agora/agora/config/…/app/models/category.rb:2
from
c:/progra~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:207:in
load' from c:/progra~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:207:in
load’
from
c:/progra~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:39:in
require_or_load' from c:/progra~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:22:in
depend_on’
from
c:/progra~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:30:in
`associate_with’
… 35 levels…
from C:/work/agora/agora/test/unit/…/test_helper.rb:3
Seems that alias could not find function find(). Where it defined?? How
could I do alias for it?? Probably there is other simplier way to
overwrite
find() method??