From 89dda76f604cb273458a905d57220560661c1a5c Mon Sep 17 00:00:00 2001 From: Spen Date: Fri, 1 Nov 2013 17:14:26 +0800 Subject: [PATCH] fix ntu ga survey export --- .../survey/back_end/surveys_controller.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 c221df87f..8e362745f 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 @@ -232,7 +232,9 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController @survey = ::Survey.find(params[:id]) @chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data - csv = CSV.generate do |csv| + head = 'EF BB BF'.split(' ').map{|a|a.hex.chr}.join() + + csv = CSV.generate(csv = head) do |csv| row = [] @survey_questions.each do |question| row << question.title @@ -277,7 +279,7 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController @survey_questions.each do |question| if question.type == ::SurveyQuestion::Radiogroup options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] - row << Hash[answer[question.id.to_s].map {|o, g| [options[o], g]}] + row << Hash[answer[question.id.to_s].map {|o, g| [options[o], g]}] if !answer[question.id.to_s].blank? else row << answer[question.id.to_s] end @@ -289,11 +291,16 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController end respond_to do |format| - format.csv do - response.headers["Content-Type"] = "text/csv; charset=big5" - render :text => csv.encode('Big5') - end + format.html + format.csv { send_data csv } end + + # respond_to do |format| + # format.csv do + # response.headers["Content-Type"] = "text/csv; charset=big5" + # render :text => csv.encode('Big5') + # end + # end end def set_answers