ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

reject_if if 2 attributes are blank #377

Closed Rubioli closed 7 years ago

Rubioli commented 7 years ago

In my application I am Rejecting nested form if my sort_order attribute is blank.

reject_if: proc { |attributes| attributes['sort_order'].blank? }

How can I make is so I can reject only IF when Both sort_order AND title is blank?

Thanks in advanced!

ToniTornado commented 7 years ago

This is easy. Your proc returns a boolean value if the entry should be rejected. So for both fields it could look like this:

reject_if: proc { |attributes| attributes['sort_order'].blank? && attributes['title'].blank? }

Rubioli commented 7 years ago

Great Thanks