import 'check' and 'select' question success

This commit is contained in:
thomaschen 2013-10-21 17:37:34 +08:00 committed by Manson Wang
parent c62d917048
commit 2ceb0167a5
1 changed files with 14 additions and 7 deletions

View File

@ -101,7 +101,7 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
else raise "Unknown file type: #{file.original_filename}"
end
@current_row = 2
@start_row = 2
@header = @spreadsheet.row(1)
# (2..@spreadsheet.last_row).each do |i|
@ -109,17 +109,24 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
# end
@survey.survey_answers.destroy
@survey_questions.each_with_index do |question,column|
@survey_questions.each_with_index do |question,index|
case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select
(@current_row..(@current_row + question.survey_question_options.count - 1)).each do |row|
(1..@spreadsheet.row(row)[column + 1].to_i).each do
(@start_row..(@start_row + question.survey_question_options.count - 1)).each do |row|
(1..@spreadsheet.row(row)[index*2 + 1].to_i).each do
@answer_model = @survey.survey_answers.new
@answer_model[question.id.to_s] = @spreadsheet.row(row)[column]
@answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2]
@answer_model.save!
end
end
@current_row = @current_row + question.survey_question_options.count - 1
end
when ::SurveyQuestion::Check
(@start_row..(@start_row + question.survey_question_options.count - 1)).each do |row|
(1..@spreadsheet.row(row)[index*2 + 1].to_i).each do
@answer_model = @survey.survey_answers.new
@answer_model[question.id.to_s] = [ @spreadsheet.row(row)[index*2] ]
@answer_model.save!
end
end
else
end
end