error fix

This commit is contained in:
thomaschen 2013-10-25 16:54:29 +08:00
parent b327a50ee3
commit ebcc13a87a
1 changed files with 90 additions and 77 deletions

View File

@ -113,29 +113,38 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@survey_answers.destroy @survey_answers.destroy
# End of speadsheet # Start and end of speadsheet
@end_row = @spreadsheet.count @end_row = @spreadsheet.count
@max_row_start = 0
@survey_questions.each do |question|
case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select, ::SurveyQuestion::Check
if question.survey_question_options.count > @max_row_start
@max_row_start = question.survey_question_options.count
end
when ::SurveyQuestion::Radiogroup
if question.survey_question_options.count * question.survey_question_radiogroups.count > @max_row_start
@max_row_start = question.survey_question_options.count * question.survey_question_radiogroups.count
end
end
end
@start_row = @max_row_start + 2
# Modify multiline options if changed # Modify multiline options if changed
(@start_row..@end_row).each do |row|
@answer_model = @survey.survey_answers.new
@survey_questions.each_with_index do |question, index| @survey_questions.each_with_index do |question, index|
case question.type case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select when ::SurveyQuestion::Radio, ::SurveyQuestion::Select
((question.survey_question_options.count + 2)..@end_row).each do |row|
@answer_model = @survey.survey_answers.new
if !@spreadsheet.row(row)[index*2].nil? && @spreadsheet.row(row)[index*2] != " " 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[question.id.to_s] = @spreadsheet.row(row)[index*2]
@answer_model.save!
end
end end
when ::SurveyQuestion::Check when ::SurveyQuestion::Check
((question.survey_question_options.count + 2)..@end_row).each do |row|
@answer_model = @survey.survey_answers.new
if !@spreadsheet.row(row)[index*2].nil? 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[question.id.to_s] = @spreadsheet.row(row)[index*2].split("\"").select.each_with_index { |str, i| i.odd? }
@answer_model.save!
end
end end
when ::SurveyQuestion::Radiogroup when ::SurveyQuestion::Radiogroup
@ -160,14 +169,14 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
# Save the answers # Save the answers
answers.each do |answer| answers.each do |answer|
options = Hash[question.survey_question_options.collect { |o| [ o.id.to_s, o.name ] }] options = Hash[question.survey_question_options.collect { |o| [ o.id.to_s, o.name ] }]
@answer_model = @survey.survey_answers.new # @answer_model = @survey.survey_answers.new
@answer_model[question.id.to_s] = {} @answer_model[question.id.to_s] = {}
answer.each do |option, value| answer.each do |option, value|
@answer_model[question.id.to_s][options.invert[option]] = value @answer_model[question.id.to_s][options.invert[option]] = value
end end
@answer_model.save! # @answer_model.save!
end end
# Parse the needed info in the array # Parse the needed info in the array
@ -213,6 +222,10 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
end end
end end
@answer_model.save!
end #end row
# @start_row = 2 # @start_row = 2
# @survey.survey_answers.destroy # @survey.survey_answers.destroy
# @survey_questions.each_with_index do |question,index| # @survey_questions.each_with_index do |question,index|