Project

tabularasa

0.0
No commit activity in last 3 years
No release in over 3 years
This Rails gem gives you the ability to call to_csv to a collection of homogenous activerecords and/or hashes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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