I have a rails 3 form with nes开发者_运维技巧ted attributes. So, for example, the parent "Shop" form has many nested "products" rows on the same form.
The "products" model has presence validations on it, but the problem is unless I fill out an entry for each product in the (nested) form, the presence validations fail.
So, in a nested form, how do I tell rails to ignore the entry if all fields for a given product are blank, but uphold presence validations if any field is filled out?
Many thanks
This should work for you:
accepts_nested_attributes_for :products, :reject_if => :all_blank, :allow_destroy => true
精彩评论