Class: Missinglink::SurveyAnswer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Missinglink::SurveyAnswer
- Defined in:
- app/models/missinglink/survey_answer.rb
Class Method Summary collapse
Class Method Details
.first_or_create_by_question_details(question_id, sm_id) ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/models/missinglink/survey_answer.rb', line 24 def self.first_or_create_by_question_details(question_id, sm_id) if new_answer = SurveyAnswer.find_by_survey_question_id_and_sm_answer_id(question_id, sm_id.to_i) return new_answer else return SurveyAnswer.create(survey_question_id: question_id, sm_answer_id: sm_id.to_i) end end |
.parse(question, hash) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/missinglink/survey_answer.rb', line 7 def self.parse(question, hash) answer = SurveyAnswer.first_or_create_by_question_details(question.id, hash['answer_id']) answer.update_attributes({ position: hash['position'].to_i, text: hash['text'], answer_type: hash['type'], visible: hash['visible'], weight: hash['weight'], apply_all_rows: hash['apply_all_rows'], is_answer: hash['is_answer'] }) answer.survey_question = question answer.save return answer end |