Ruby on rails 如果选项被忽略,则拒绝\u

Ruby on rails 如果选项被忽略,则拒绝\u,ruby-on-rails,ruby-on-rails-3.2,Ruby On Rails,Ruby On Rails 3.2,以下是(简化)代码: class Biosimilar::DisposteEvent'Biosimilar::happeeventmedcond', :dependent=>:destroy 有很多:中等条件, :class_name=>'Biosimilar::MedCond', :至=>:不良事件\u中等情况 接受\u嵌套的\u属性\u用于:不利事件\u中等情况, :allow_destroy=>true, :reject|if=>proc{| attributes | attributes

以下是(简化)代码:

class Biosimilar::DisposteEvent'Biosimilar::happeeventmedcond',
:dependent=>:destroy
有很多:中等条件,
:class_name=>'Biosimilar::MedCond',
:至=>:不良事件\u中等情况
接受\u嵌套的\u属性\u用于:不利事件\u中等情况,
:allow_destroy=>true,
:reject|if=>proc{| attributes | attributes.any?{| k,v | v.blank?}
终止
提交表单时,即使用户将“不良事件”字段留空,也会在“不良事件”表中创建记录。如果不起作用,则拒绝_


有什么建议吗?

好的,算了吧。以上代码是正确的!问题出在控制器上,我无意中在“显示”方法中留下了以下行:

if @adverse_event.adverse_event_med_conds.size == 0
  @adverse_event.adverse_event_med_conds.build
end

…而“build”调用是导致记录创建的调用。

如果显式检查该属性会发生什么?例如,
:如果=>proc{attributes}attributes['med_cond_id'],则拒绝。空白?}
if @adverse_event.adverse_event_med_conds.size == 0
  @adverse_event.adverse_event_med_conds.build
end