asdfkjasdfjk
asdfkjasdfjk

Reputation: 3894

reject accepts_nested_attributes_for multiple field blank

In my rails 4 app, I am using

 `accepts_nested_attributes_for :application, reject_if: proc { |attributes| attributes['uni_id'].blank? }` 

But now I need to check it for multiple options. The pseudocode for what I want is something like this

accepts_nested_attributes_for :application, reject_if: proc {
  (attributes['uni_id'].blank?  and attributes['duration'].blank?) OR (attributes['uni_id'].blank?  and attributes['semester'].blank?)

}

That is, reject if (attributes['uni_id'].blank? and attributes['duration'].blank?) OR (attributes['uni_id'].blank? and attributes['semester'].blank?)

Hope there might be some easy solution for this.

Upvotes: 2

Views: 365

Answers (1)

asdfkjasdfjk
asdfkjasdfjk

Reputation: 3894

This is working for me

accepts_nested_attributes_for :application, reject_if: proc { |attributes| 
  (attributes['uni_id'].blank?  && attributes['duration'].blank?) || (attributes['uni_id'].blank?  && attributes['semester'].blank?)

}

Upvotes: 2

Related Questions