We have a Rails application in which an after_create is dynamically added to an ActiveRecord model from an initializer.
We've tried instance_eval
Foo.instance_eval do
send "after_create", lambda{|r| r.some_method}
end
and class_eval
Foo.class_eval do
after_create lambda{|r| r.some_method}
end
When running Foo.new._create_callbacks
just after creating them it returns both of the callbacks.
After doing a request to the Rails server the two callbacks disappear.
This problem only happens in development. Staging and Production are working fine.
When setting the config.cache_classes = true
in the development.rb
the callbacks will persist and not disappear.
We have replicated this code in other applications and it works fine, so maybe it is a configuration issue.
NOTE: We are using subdomains with lvh.me
- Rails 3.1.1
- Ruby 1.9.2-p180
Thanks :)