Sha256: ba93b0bb97c9158f861fd9668fcda11055840cba9871e9fa2dcb5b0cde534186
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
class Answer < ActiveRecord::Base if respond_to? :attr_accessible # Rails 3.2 backwards compatibility attr_accessible :question_id, :answer, :choice_id, :uploaded_file, :uploaded_file_cache end belongs_to :answerer, :polymorphic => true belongs_to :question belongs_to :choice validates_presence_of :question_id mount_uploader :uploaded_file, UploadedFileUploader default_scope lambda { joins(:question).order('questions.position').readonly(false) } # This scope prevents updating answers unless readonly is set to false. scope :for_answerer, lambda{|answerer| where(:answerer_type => answerer.class.to_s, :answerer_id => answerer.id)} scope :for_question, lambda{|question| where(:question_id => question.id)} def to_s if question.supports_uploads? self.uploaded_file.url else self.answer.to_s end end # This method is used to see if the answer fails to meat "required" status if the question is required. # should return true on fail and nil/false on success. def fails_required? if question.required if question.supports_uploads? uploaded_file.blank? else answer.blank? end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ask-0.5.4 | app/models/answer.rb |
ask-0.5.3 | app/models/answer.rb |