Sha256: 1967270d674ee4e5788df752942e207ea9ce117e609bbe1984423d70ac983296
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
class Question < ActiveRecord::Base require 'acts_as_list' TYPES = ['TextQuestion', 'EssayQuestion', 'ChooseOneQuestion', 'ChecklistQuestion', 'UploadQuestion', 'FormSection'] belongs_to :asker, :polymorphic => true has_many :choices, :dependent => :destroy has_many :answers, :dependent => :destroy acts_as_list :scope=>:asker if respond_to? :attr_accessible # Rails 3.2 backwards compatibility attr_accessible :type, :name, :instructions, :required, :choices_attributes, :position end accepts_nested_attributes_for :choices, :allow_destroy=>true, :reject_if=>lambda{|attrs| attrs['name'].blank? } validates_presence_of :type, :name validates_inclusion_of :type, :in=>TYPES validate :form_section_not_required default_scope lambda { order(:position) } scope :required, -> { where(:required => true) } def attributes_protected_by_default default = [ self.class.primary_key ] default << 'id' unless self.class.primary_key.eql? 'id' default end # This just means it doesn't expect an answer, such as a form_section question def rhetorical? false end def supports_choices false end def choice_names return [] unless supports_choices self.choices.map(&:name) end def supports_multiple_answers? false end def supports_uploads? false end private def form_section_not_required if type == 'FormSection' && required? errors.add :required, 'cannot be true for form sections' end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ask-0.5.4 | app/models/question.rb |
ask-0.5.3 | app/models/question.rb |