开发者

Rails 3 nested validations: Ignoring entry if all fields are blank?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜