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

ad583255925 · 2017年06月18日 · 最后由 brook 回复于 2017年10月11日 · 1699 次阅读
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? 这个在字段被修改但未保存的情况下也有用,这个替代不了,怎么办?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号