1
这里是(简化)代码:reject_if选项被忽略
class Biosimilar::AdverseEvent < ActiveRecord::Base
attr_accessibile :adverse_event_med_conds_attributes
has_many :adverse_event_med_conds,
:class_name => 'Biosimilar::AdverseEventMedCond',
:dependent => :destroy
has_many :med_conds,
:class_name => 'Biosimilar::MedCond',
:through => :adverse_event_med_conds
accepts_nested_attributes_for :adverse_event_med_conds,
:allow_destroy => true,
:reject_if => proc { |attributes| attributes.any? {|k,v| v.blank?} }
end
当提交表单时,该记录上,即使用户离开“med_cond_id”字段为空“adverse_event_med_conds”表中创建。 reject_if不起作用!
有什么建议吗?
如果您明确检查该属性会发生什么?例如。 '':reject_if => proc {| attributes |属性[ 'med_cond_id']。空白? }'' – GSP