From nested_attributes API
You can also set: reject_if proc to silently ignore any new hashes of the record if they cannot pass your criteria.
params = { member: { name: 'joe', order_attributes: [ { description: 'Kari, the awesome Ruby documentation browser!' }, { description: 'The egalitarian assumption of the modern citizen' }, { description: '', _destroy: '1' }
Any hash with a description space will be completely ignored, even if it has the _destroy flag.
If you want to delete entries with a blank description, I can think of two solutions
Option 1: delete them with a callback in your model:
before_save :remove_orders_without_description def remove_orders_without_description orders.select{|o| o.description.blank?}.each(&:delete) end
Option 2: remove the reject_if parameter in the model definition and use JS in the view to set the _delete attribute _delete
source share