fix ntu ga survey export

This commit is contained in:
Spen 2013-11-01 17:14:26 +08:00
parent 82988a2029
commit 89dda76f60
1 changed files with 13 additions and 6 deletions

View File

@ -232,7 +232,9 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@survey = ::Survey.find(params[:id]) @survey = ::Survey.find(params[:id])
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data @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 = [] row = []
@survey_questions.each do |question| @survey_questions.each do |question|
row << question.title row << question.title
@ -277,7 +279,7 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@survey_questions.each do |question| @survey_questions.each do |question|
if question.type == ::SurveyQuestion::Radiogroup if question.type == ::SurveyQuestion::Radiogroup
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 ] }]
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 else
row << answer[question.id.to_s] row << answer[question.id.to_s]
end end
@ -289,11 +291,16 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
end end
respond_to do |format| respond_to do |format|
format.csv do format.html
response.headers["Content-Type"] = "text/csv; charset=big5" format.csv { send_data csv }
render :text => csv.encode('Big5')
end
end end
# respond_to do |format|
# format.csv do
# response.headers["Content-Type"] = "text/csv; charset=big5"
# render :text => csv.encode('Big5')
# end
# end
end end
def set_answers def set_answers