在由于验证错误而失败的表单提交上,我需要隐藏已标记为destroy的表单元素。
我正在使用accepts_nested_attributes_for,它会在表单中添加_destroy字段。如何在表单提交后访问此字段的值?
>> f2.hidden_field :_destroy
=> "<input type=\"hidden\" value=\"true\" ...
>> f2.object[:_destroy]
=> nil
Id和其他属性按预期工作。
>> f2.object[:id]
=> 10
答案 0 :(得分:2)
你可以查看Object.marked_for_destruction吗?如果它是真的那么记录标记,
代码
if f2.marked_for_destruction?
# your code here
end