I'm trying render the results of surveys from Surveryor gem as a CSV file, but get a "Template is missing" error.
For example, localhost:3000/results/user-feedback-survey-1.csv
results in:
Template is missing
Missing template results/show, application/show with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:csv], :locale=>[:en, :en]}. Searched in: * "/websites/surveyportal/app/views" * "/usr/local/lib/ruby/gems/1.9.1/gems/surveyor-0.21.0/app/views"
Same error for .json
. I've added gem 'fastercsv'
to my gem file.
Is there something I'm missing? I'm using Rails 3.1.3.
I'm sure there is a much better way then this, but I was able to make it work with the following code, which I gleaned from a deleted version of the Surveyor gem show.html.erb file.
<% csvString = "id, Code, " %>
<% @questions.each do |question| %>
<% next if question.display_order == 1 %>
<% csvString += "[" +question.display_order.to_s + "]" + question.text.to_s + "," %>
<% end %>
<% csvString += "\n" %>
<% @response_sets.each do |r_set| %>
<% csvString += r_set.id.to_s + "," + r_set.access_code.to_s %>
<% @questions.each do |question| %>
<% next if question.display_order == 1 %>
<% csvString += display_response(r_set,question).to_s + "," %>
<% end %>
<% csvString += "\n" %>
<% end %>
<%= csvString %>
I added it to the /app/views/results/show.csv.erb
file.