私はこのモデルを持っています:
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
ここでの問題は、新しいコンテスト エントリを作成すると、それが通過することです。しかし、1 つのフィールド、つまり名前を入力すると、エラーが発生します。
なぜこうなった?すべてが空の場合は失敗するはずです!