CSV template Rails plugin - this is now unmaintained - please use https://github.com/gtd/csv_builder instead
Latest commit df19e65 May 21, 2013 Lewis Marshall Update link to maintained version
Failed to load latest commit information.
.gitignore Added README, license, and rdoc rake task Jun 26, 2008
MIT-LICENSE Added README, license, and rdoc rake task Jun 26, 2008
README.rdoc Update link to maintained version May 21, 2013
Rakefile Added README, license, and rdoc rake task Jun 26, 2008
init.rb Initial commit Jun 26, 2008


CSV Builder

Please note:

We no longer maintain this plugin - if you want to make use of it then we recommend you use Gabe da Silveira's fork github.com/gtd/csv_builder. Gabe is actively maintaining his fork and has already converted it into a gem and upgraded it to work with Rails 3.

The CSV Builder Rails plugin provides a simple templating system for serving dynamically generated CSV files from your application.


CSV Builder requires Rails v2.1.

It also depends upon the FasterCSV gem fastercsv.rubyforge.org, which you can install with

$ sudo gem install fastercsv

Encoding conversions are done with Iconv, so make sure you have it on your development/production machine.


CSV template files are suffixed with '.csv.csvbuilder', for example 'index.csv.csvbuilder'

Add rows to your CSV file in the template by pushing arrays of columns into the csv object.

# First row
csv << [ 'cell 1', 'cell 2' ]
# Second row
csv << [ 'another cell value', 'and another' ]
# etc...

You can set the default filename for that a browser will use for 'save as' by setting @filename instance variable in your controller's action method e.g.

@filename = 'report.csv'

You can set the input encoding and output encoding by setting @input_encoding and @output_encoding instance variables. These default to 'UTF-8' and 'LATIN1' respectively. e.g.

@output_encoding = 'UTF-8'

You can set @csv_options instance variable to define options for FasterCSV generator. For example:

@csv_options = { :force_quotes => true, :col_sep => ';' }

You can also attach a csv file to mail sent out by your application by including a snippet like the following in your mailer method

attachment "text/csv" do |attachment|
  attachment.body = render(:file => 'example/index.csv.csvbuilder')
  attachment.filename = 'report.csv'

Copyright © 2008 Econsultancy.com and 2009 Vidmantas Kabošis, released under the MIT license.