我在类中有一个 :reject_if 的accepts_nested_attributes_for 案例,但我也希望能够在某个值为 0 时销毁已创建的对象。
似乎没有 :destroy_if 选项。是否有标准方法来控制此类情况?
最佳答案
我找到了使用 before_save 的解决方案。这看起来效果很好。
before_save :mark_entries_for_removal
def mark_entries_for_removal
entries.each do |entry|
entry.mark_for_destruction if entry.hours_spent <= 0
end
end
关于ruby-on-rails - 接受嵌套属性 :destroy_if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15480926/