class Horse < ActiveRecord::Base
attr_accessible :body_scores_attributes
has_many :body_scores, :dependent => :destroy
accepts_nested_attributes_for :body_scores, :reject_if => :reject_body_scores
private
def reject_body_scores(attributed)
new_record? || attributed['date'].blank? || attributed['score'].blank?
end
end
和
class BodyScore < ActiveRecord::Base
attr_accessible :horse_id, :score, :scoring_date
belongs_to :horse
validates :horse_id, :score, :scoring_date, :presence => true
end