我有这个模型:
class CompetitionEntry < ActiveRecord::Base
has_many :participants
has_one :address
has_many :music_programs
accepts_nested_attributes_for :address
accepts_nested_attributes_for :participants, :music_programs,
:allow_destroy => true,
:reject_if => :all_blank
end
和这个:
class Participant < ActiveRecord::Base
belongs_to :competition_entry
has_one :birthplace
validates :name, :surname, :instrument, presence: true
end
现在的问题是,如果我创建一个新的竞赛条目,它就会通过。但是如果我填写一个字段,即名称,那么它会出现错误!
为什么会这样?当所有内容都为空时,它应该会失败!