Rails Rails5.1 有个 attribute_changed?问题你们知道怎么解决吗

ad583255925 · June 18, 2017 · Last by brook replied at October 11, 2017 · 1698 hits
def reorder?
 p 'it works' if self.order_num_changed?
end

当我准备在回调里调用 attribute_changed?的时候,会出来一句

DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from attribute_changed? at /Users/jiyarong/.rvm/gems/ruby-2.3.0@global/gems/activerecord-5.1.1/lib/active_record/attribute_methods/dirty.rb:225)

你不要在 after_save 里面调用这个

刚遇到同样问题,使用 saved_changes 方法代替 attribute_changed

saved_change_to_attribute? 无法在 before_save 的情况下起作用。attribute_changed? 这个在字段被修改但未保存的情况下也有用,这个替代不了,怎么办?

You need to Sign in before reply, if you don't have an account, please Sign up first.