Sha256: a447fb2c478765964eaad5c37fb7765db32ebce17fd6b46f62e0323d5e401d97

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

class Answer < ActiveRecord::Base

  attr_accessible :question_id, :answer, :choice_id, :uploaded_file, :uploaded_file_cache
  
  belongs_to :answerer, :polymorphic => true
  belongs_to :question
  belongs_to :choice

  validates_presence_of :question_id

  mount_uploader :uploaded_file, UploadedFileUploader

  default_scope joins(:question).order('questions.position')
  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

1 entries across 1 versions & 1 rubygems

Version Path
ask-0.5.0 app/models/answer.rb