Fel*_*ger 0 ruby-on-rails callback ruby-on-rails-4
当我检测到已更改且即将更新时,我尝试更改attribute_1值。attribute_2
对象已更新,但设置的attribute_1值并未持续存在,为什么?
before_update :check_attribute2_change
def check_attribute_2_change
if attribute_2_changed?
attribute_1 = nil
end
end
Run Code Online (Sandbox Code Playgroud)
尝试这个:
before_update :check_attribute2_change
def check_attribute_2_change
self.attribute_1 = nil if attribute_2_changed?
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1753 次 |
| 最近记录: |