Whcih is the best way to export a table as csv ? I already have the
table I want to export as a 2d array, and has disabled the layout for
that view. But I am bit confused about the final output, my current
pathetic attempt at CSV writing is
<% for row in @report
for cell in row
puts (cell)
end
end %>
I would do it in a class method, then render :text.
Also, you could do
@headers["Content-Type"] = "text/plain"
to cause the browser to want to download instead of display the data.
Whcih is the best way to export a table as csv ? I already have the
table I want to export as a 2d array, and has disabled the layout for
that view. But I am bit confused about the final output, my current
pathetic attempt at CSV writing is
<% for row in @report
for cell in row
puts (cell)
end
end %>
Get the FasterCSV gem. Once you’ve got it, require it in environment.rb. Here’s an abbreviated version of my working controller method. Copy/paste/modify. And you’re done!