Agile Web Development

Build it. Launch it. Love it.

to_csv

This plugin provides support for responding to the CSV format, as well as exporting a collection of ActiveRecord objects to CSV.

./script/plugin install -x http://svn.integralserver.com/plugins/to_csv

You can simply take a collection of ActiveRecord objects and apply the to_csv method to them:

@users = User.find(:all) @users.to_csv

For a more RESTful way of exporting a CSV, do something like this in your controller:

respond_to do |wants|

  wants.csv do
    render :text => @users.to_csv
    response.headers['Content-Type'] = 'text/csv; charset=iso-8859-1; header=present'
    response.headers['Content-Disposition'] = "attachment; filename=users_#{Time.now.strftime("%m-%d-%Y")}.csv"
  end

end


Copyright © 2006 Chris Abad released under the MIT license

Vitals

Home http://blog.integralimpressions.com/articles/2006/09/01/tocsv-plugin
Repository http://svn.integralserver.com/plugins/to_csv
License Rails' (MIT)
Rating (10 votes)
Owner Chris Abad
Created 1 September 2006

Comments

  • 28 September 2007

    you have error in code.. fix line 35 delimeter => delimiter

Add a comment