tabularasa gem¶ ↑
This simple gem gives you the ability to convert an array of activerecords, hashes, and/or arrays to tabular data.
Usage¶ ↑
@users = User.all # # defaults are export headers and all fields # @users.to_csv @users.to_csv(:only => [:last_name, :role]) # This will also set the order @users.to_csv(:delimiter => ';') # This will set the delimiter between values in a row @users.to_csv(:headers => ["Last Name", "Role"]) @users.to_csv(:except => [:last_name, :role])
Real life example¶ ↑
class UserController < ApplicationController def index @users = User.all respond_to do |format| format.html format.xml { render :xml => @users } format.csv { send_data @users.to_csv } end end end
Dependencies¶ ↑
ruby >= 1.9 * activerecord ruby < 1.9 * activerecord * fastercsv
Install¶ ↑
gem install tabularasa
Contributors¶ ↑
-
Chris Rosario
Copyright © 2011 Chris Rosario, released under the MIT license