This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 0f3bfb223684532250e0b3dc6647113673adcb56
tree 7e0bd23888687b2f1b6be062733081b0993f6bf3
parent 07c1fb93d9f2ebffd1fe2cea5197cb7ecbca996a
tree 7e0bd23888687b2f1b6be062733081b0993f6bf3
parent 07c1fb93d9f2ebffd1fe2cea5197cb7ecbca996a
to_csv /
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Wed Jun 11 12:46:07 -0700 2008 | |
| |
README.rdoc | Tue Dec 23 14:04:46 -0800 2008 | |
| |
init.rb | Tue Jul 29 14:02:13 -0700 2008 | |
| |
lib/ | Thu Jul 30 07:31:39 -0700 2009 | |
| |
test/ | Mon Feb 16 10:23:08 -0800 2009 |
README.rdoc
to_csv plugin
This simple plugin gives you the ability to call to_csv to a collection of activerecords. The builder options are the same as to_json / to_xml, except for the :include.
Usage
@users = User.all # # defaults are export headers and all fields # @users.to_csv @users.to_csv(:only => [:last_name, :role]) @users.to_csv(:headers => false) @users.to_csv(:except => [:last_name, :role]) @users.to_csv(:except => :role, :methods => :admin?)
Real life example
In the controller where you want to export to csv, add the format.csv line (as of rails 2.1 it is not necessary to register the csv myme_type)
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
def show...
def new...
def edit...
def create...
def update...
def destroy...
end
Dependencies
sudo gem install fastercsv
Install
./script/plugin install git://github.com/arydjmal/to_csv.git
Ideas
I got ideas and influence from Mike Clarks recipe #35 in Rails Recipes book, some anonymous pastie, and whoever wrote to_xml/to_json builders.
Note
Does not work on a single activerecord, ie, User.first.to_csv.
Copyright © 2008 Ary Djmal, released under the MIT license







