On a form submit that fails because of a validation error, I need to hide form elements that have been marked for destroy.
I'm using accepts_nested_attributes_for, which adds a _destroy field to the form. How do I access the value of this field after a form submit?
>> f2.hidden_field :_destroy
=> "<input type=\"hidden\" value=\"true\" ...
>> f2.object[:_destroy]
=> nil
Id and other attributes work as expected.
>> f2.object[:id]
=> 10
you can check with Object.marked_for_destruction? if it's true then the record marked,
for your code
if f2.marked_for_destruction?
# your code here
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.