title: in rails, how to return records as a csv file
body: <p>I have a simple database table called "Entries":</p>
  
  <pre><code>class CreateEntries &lt; ActiveRecord::Migration
    def self.up
      create_table :entries do |t|
        t.string :firstName
        t.string :lastName
        #etc.
        t.timestamps
      end
    end
  
    def self.down
      drop_table :entries
    end
  end
  </code></pre>
  
  <p>How do I write a handler that will return the contents of the Entries table as a CSV file (ideally in a way that it will automatically open in Excel)?</p>
  
  <pre><code>class EntriesController &lt; ApplicationController
  
    def getcsv
      @entries = Entry.find( :all )
  
      # ??? NOW WHAT ????
  
    end
  
  end
  </code></pre>