Plugins - to_csv

StarAdd to favorites

to_csv

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

Installation

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

Usage

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

Chris Abad

http://blog.integralimpressions.com/articles/2006/09/01/tocsv-plugin

http://svn.integralserver.com/plugins/to_csv

Rails' (MIT)

  • Currently 3.1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Controllers

Tags

Comments

Add a comment
cyner 28 Sep 2007

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

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?