From 62e9acdbb828d95fd74504c9608d8a1dec4f5471 Mon Sep 17 00:00:00 2001 From: thomaschen <99703040@nccu.edu.tw> Date: Fri, 25 Oct 2013 15:35:48 +0800 Subject: [PATCH] fix error --- .../survey/back_end/surveys_controller.rb | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb index 717b1c16c..88d642456 100644 --- a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb @@ -110,27 +110,29 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController end @survey.survey_answers.destroy + + # End of speadsheet + @end_row = @spreadsheet.count # Modify multiline options if changed @survey_questions.each_with_index do |question, index| case question.type - when ::SurveyQuestion::Radio, ::SurveyQuestion::Select - (2..(question.survey_question_options.count + 1)).each do |row| - (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do + ((question.survey_question_options.count + 2)..@end_row).each do |row| @answer_model = @survey.survey_answers.new - @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2] - @answer_model.save! - end + if !@spreadsheet.row(row)[index*2].nil? && @spreadsheet.row(row)[index*2] != " " + @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2] + @answer_model.save! + end end when ::SurveyQuestion::Check - (2..(question.survey_question_options.count + 1)).each do |row| - (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do + ((question.survey_question_options.count + 2)..@end_row).each do |row| @answer_model = @survey.survey_answers.new - @answer_model[question.id.to_s] = [ @spreadsheet.row(row)[index*2] ] - @answer_model.save! - end + if !@spreadsheet.row(row)[index*2].nil? + @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2].split("\"").select.each_with_index { |str, i| i.odd? } + @answer_model.save! + end end when ::SurveyQuestion::Radiogroup