fix ntu ga survey export

This commit is contained in:
Spen 2013-11-01 17:14:26 +08:00 committed by Manson Wang
parent d6d7d3ee66
commit b3894c4ada
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])
@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