【发布时间】:2012-12-23 09:46:13
【问题描述】:
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
【问题讨论】:
标签: unit-testing rspec