Class: Missinglink::SurveyPage
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Missinglink::SurveyPage
- Defined in:
- app/models/missinglink/survey_page.rb
Class Method Summary collapse
Class Method Details
.first_or_create_by_survey_details(survey_id, sm_id) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/models/missinglink/survey_page.rb', line 22 def self.first_or_create_by_survey_details(survey_id, sm_id) # spelling this one out more explicitly so it's easier to test if new_page = SurveyPage.find_by_survey_id_and_sm_page_id(survey_id, sm_id.to_i) return new_page else return SurveyPage.create(survey_id: survey_id, sm_page_id: sm_id.to_i) end end |
.parse(survey, hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/missinglink/survey_page.rb', line 9 def self.parse(survey, hash) page = first_or_create_by_survey_details(survey.id, hash['page_id']) page.update_attributes({heading: hash['heading'], sub_heading: hash['sub_heading']}) hash['questions'].each do |question| SurveyQuestion.parse(page, question) end return page.reload end |