import radio question success
This commit is contained in:
parent
ea3edbf7ac
commit
dec6087850
2
Gemfile
2
Gemfile
|
@ -29,7 +29,7 @@ gem 'mongoid-tree', :require => 'mongoid/tree'
|
|||
gem "mongo_session_store-rails3", '3.0.6'
|
||||
gem 'nokogiri'
|
||||
|
||||
# export csv
|
||||
# import csv
|
||||
gem 'roo'
|
||||
|
||||
gem 'fb_graph'
|
||||
|
|
|
@ -94,7 +94,8 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
|||
def import
|
||||
@survey = ::Survey.find(params[:id])
|
||||
@file = params[:file]
|
||||
|
||||
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
|
||||
|
||||
case File.extname(@file.original_filename)
|
||||
when ".csv" then @spreadsheet = Roo::CSV.new(@file.path)
|
||||
# when ".xls" then Excel.new(file.path, nil, :ignore)
|
||||
|
@ -102,9 +103,27 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
|||
else raise "Unknown file type: #{file.original_filename}"
|
||||
end
|
||||
|
||||
@current_row = 2
|
||||
@header = @spreadsheet.row(1)
|
||||
(2..@spreadsheet.last_row).each do |i|
|
||||
##parse each row here
|
||||
|
||||
# (2..@spreadsheet.last_row).each do |i|
|
||||
# parse each row here
|
||||
# end
|
||||
|
||||
@survey.survey_answers.destroy
|
||||
@survey_questions.each do |question|
|
||||
case question.type
|
||||
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select
|
||||
(@current_row..(@current_row + question.survey_question_options.count - 1)).each do |i|
|
||||
(1..@spreadsheet.row(i)[1].to_i).each do
|
||||
@answer_model = @survey.survey_answers.new
|
||||
@answer_model[question.id.to_s] = @spreadsheet.row(i)[0]
|
||||
@answer_model.save!
|
||||
end
|
||||
end
|
||||
@current_row = @current_row + question.survey_question_options.count - 1
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to panel_survey_back_end_surveys_url, :notice => :success
|
||||
|
|
Loading…
Reference in New Issue