I have a simple database table called \"Entries\":
class CreateEntries < ActiveRecord::Migration
def self.up
create_table :entries do |t|
t.st
You need to set the Content-Type header in your response, then send the data. Content_Type: application/vnd.ms-excel should do the trick.
You may also want to set the Content-Disposition header so that it looks like an Excel document, and the browser picks a reasonable default file name; that's something like Content-Disposition: attachment; filename="#{suggested_name}.xls"
I suggest using the fastercsv ruby gem to generate your CSV, but there's also a builtin csv. The fastercsv sample code (from the gem's documentation) looks like this:
csv_string = FasterCSV.generate do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end