拒绝accepted_nested_attributes_for多个字段为空

时间:2015-11-10 16:19:57

标签: ruby-on-rails ruby-on-rails-4

在我的rails 4 app中,我正在使用

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

但现在我需要检查它有多种选择。我想要的伪代码是这样的

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?)

}

即,拒绝(attributes['uni_id'].blank? and attributes['duration'].blank?) OR (attributes['uni_id'].blank? and attributes['semester'].blank?)

希望可能有一些简单的解决方案。

1 个答案:

答案 0 :(得分:0)

这对我有用

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

}