Sha256: 633aeeb7a1a97ad683481bbf7d8e6979c6eac81164211aee2977f3854b11f59a

Contents?: true

Size: 642 Bytes

Versions: 3

Compression:

Stored size: 642 Bytes

Contents

class Answer < ActiveRecord::Base

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

  validates_presence_of :question_id
  validates_presence_of :answer, :if=>lambda{|answer| !answer.question.is_a?(ChecklistQuestion) && answer.question.required }

  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
    self.answer.to_s
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ask-0.1.2 app/models/answer.rb
ask-0.1.1 app/models/answer.rb
ask-0.1.0 app/models/answer.rb