Sha256: 4fb2a63c4b8c24ab028b8e1eb1d9302df52d006988403774f93f6caec010a55f

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

class Answer < ActiveRecord::Base
  belongs_to :question
  has_many :scores
  has_many :survey_images,:as         => :imageable,
                          :order      => :position,
                          :dependent  => :destroy

  validates :question_id, :presence => true
  validates :details,     :presence => true

  accepts_nested_attributes_for :scores, :reject_if => proc { |attributes| attributes['value'].blank? }
  accepts_nested_attributes_for :survey_images, :reject_if => proc { |attributes| attributes['photo'].nil? }

  def display_position
    position ? position.to_s : '*'
  end

  def image(s = :small)
    survey_images.first ? survey_images.first.photo.url(:small) : ''
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
survey_says-0.0.2 app/models/answer.rb
survey_says-0.0.1 app/models/answer.rb