survey/app/models/survey_question_option.rb

31 lines
846 B
Ruby

class SurveyQuestionOption
include Mongoid::Document
field :name, :localize => true
field :jump_to, :default => 0
field :points, :type => Integer, :default => 0
field :question_type, :type => Integer, :default => 0
embeds_many :level2, class_name: "SurveyQuestionOptionLevel2"
accepts_nested_attributes_for :level2, class_name: "SurveyQuestionOptionLevel2", :allow_destroy => true
embedded_in :survey_question
#def attributes()
# tmp = super()
# tmp.merge({name_translations: tmp[:name], qid: tmp[:_id].to_s})
#end
def as_json(**xargs)
res = super({:except =>:level2}.merge(xargs))
res.merge({name_translations: self.name_translations, qid: self[:_id].to_s, level2: self.level2.as_json})
end
def level2_radio
self.question_type==0
end
def level2_check
self.question_type==1
end
end