In my InvoicesController
I have this:
def index
@invoices = current_user.invoices
respond_to do |format|
format.html
format.xls
form
I recently discovered
render_csv
maybe check out this railscast (yay)
Try specifying the appropriate content headers and explicitly rendering your index.csv.erb
template in your format.csv
handler block.
# app/controllers/invoices_controller.rb
format.csv do
response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename=invoice.csv'
render :template => "path/to/index.csv.erb"
end
Try this
format.csv do
response.headers["Content-Type"] = "text/csv; charset=UTF-8; header=present"
response.headers["Content-Disposition"] = "attachment; filename=invoices.csv"
end