【发布时间】:2013-04-01 07:43:07
【问题描述】:
我想在模型更新之前检测属性是否发生了变化。
我有以下(基于:http://api.rubyonrails.org/classes/ActiveModel/Dirty.html):
before_update :changed_attributes
def changed_attributes
self.path_changed? ? puts('Path was changed') : puts('Path was not changed')
end
但现在当我尝试编辑 Model.path 属性时,出现以下错误:
SystemStackError: stack level too deep
我听说这意味着正在发生无限递归。
在不创建 SystemStackError 的情况下执行此操作的正确方法是什么?
【问题讨论】:
标签: ruby-on-rails model attributes callback