This:
accepts_nested_attributes_for :photo,
:reject_if => proc { |attributes| attributes[ image ].blank? },
:reject_if => proc { |attributes| attributes[ photo_title ].blank? },
:allow_destroy => true
这与这一点相同:
accepts_nested_attributes_for :photo, {
:reject_if => proc { |attributes| attributes[ image ].blank? },
:reject_if => proc { |attributes| attributes[ photo_title ].blank? },
:allow_destroy => true
}
粗鲁的论据实际上是哈希语,但鲁比拉在你背后基本上添加了bra。 A Hash don t允许重复钥匙,即第二个<代码>:reject_if 价值超过第一种标准,最后是:
accepts_nested_attributes_for :photo,
:reject_if => proc { |attributes| attributes[ photo_title ].blank? },
:allow_destroy => true
你们可以把这两种条件结合起来,以便:
accepts_nested_attributes_for :photo,
:reject_if => proc { |attributes| attributes[ image ].blank? || attributes[ photo_title ].blank? },
:allow_destroy => true
也可以使用单独的方法:
accepts_nested_attributes_for :photo,
:reject_if => :not_all_there,
:allow_destroy => true
def not_all_there(attributes)
attributes[ image ].blank? || attributes[ photo_title ].blank?
end