启用cache_classes会导致ActiveRecord :: Relation:Class的未定义方法`increment_counter'

时间:2011-09-03 13:10:36

标签: ruby-on-rails ruby-on-rails-3 activerecord

升级到Rails 3.0.10后,如果设置config.cache_classes = true,我会收到奇怪的错误

NoMethodError (undefined method increment_counter' for ActiveRecord::Relation:Class): activerecord (3.0.10) lib/active_record/associations.rb:1553:inbelongs_to_counter_cache_after_create_for_form' activesupport (3.0.10) lib/active_support/callbacks.rb:424:in _run_create_callbacks' activerecord (3.0.10) lib/active_record/callbacks.rb:277:increate' activerecord (3.0.10) lib/active_record/persistence.rb:257:in create_or_update' activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update' activesupport (3.0.10) lib/active_support/callbacks.rb:444:in _run_save_callbacks' activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update' activerecord (3.0.10) lib/active_record/persistence.rb:60:in save!' activerecord (3.0.10) lib/active_record/validations.rb:49:insave!' activerecord (3.0.10) lib/active_record/attribute_methods/dirty.rb:30:in `save!' ...

我正在保存与计数器缓存具有belongs_to关系的答案模型:

increment_counter' for ActiveRecord::Relation:Class):
  activerecord (3.0.10) lib/active_record/associations.rb:1553:in

最奇怪的是,在服务器重新启动后,第一次保存工作正常,之后我开始得到这样的异常。

也许有人可以建议我可以从哪里开始寻找原因?

1 个答案:

答案 0 :(得分:1)

问题是由过时的acts_as_taggable_on_steroids gem导致的,这导致了Rails3的类缓存问题。切换到可以标记为宝石的行为 - 解决了问题。