lib/ask/acts_as_answerer.rb in ask-0.1.2 vs lib/ask/acts_as_answerer.rb in ask-0.2.0

- old
+ new

@@ -64,10 +64,20 @@ qa[a.question.name] << a.answer.to_s.strip unless a.answer.blank? end qa end + + private + + def validate_required_questions + event.questions.required.each do |question| + if answers.select{|a| a.question_id == question.id}.all?{|a| a.answer.blank?} + errors[:base] << "\"#{question.name}\" is required" + end + end + end end end end @@ -78,7 +88,9 @@ has_many :answers, :as => :answerer, :dependent=>:destroy has_many :questions, :through=>:answers attr_accessible :answers_attributes accepts_nested_attributes_for :answers, :allow_destroy=>true + + validate :validate_required_questions end end