为什么update_attributes没有在我的模型中调用before_validation回调

sum*_*man 0 ruby-on-rails

我正在使用rails 2.3.8版本有任何特殊原因,为什么update_attributes不会触发before_validation回调

class x < ActiveRecord::Base
before_validation :testing

def testing
  debugger
end
end
Run Code Online (Sandbox Code Playgroud)

x.update_attributes(:name =>"hello")不会触发before_validation

Log*_*man 5

如果您使用Google搜索此方法,答案将非常清楚:这里是明确指出update_attribute不会通过验证过程的文档.update_attributes如果要触发验证,则应使用.

  • 原始问题提到了“update_attributes”,而不是“update_attribute”。 (2认同)