Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (31 sloc) 1.051 kB
08f0e2b rename to-csv-rails to to_csv-rails
wenke authored
1 == to_csv on Rails
6b5e79d update readme file
wenke authored
2
c1ee4ef update readme file
wenke authored
3 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.
6b5e79d update readme file
wenke authored
4
5
6 == Usage
7
4cd2cdc cleanup
wenke authored
8 @posts = Post.all
9
10 #
11 # default are export header and all fileds
12 #
13
6b5e79d update readme file
wenke authored
14 @posts.to_csv
15 @posts.to_csv(:only => [:title, :body])
16 @posts.to_csv(:except => [:id])
17 @posts.to_csv(:header => false)
18
19
20 == Example
21
22 class PostsController < ApplicationController
23 def index
24 @posts = Post.all
25
26 respond_to do |format|
27 format.csv { send_data(@posts.to_csv) }
28 #format.csv {
f0e678e
wenke authored
29 # filename = "posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.csv"
6b5e79d update readme file
wenke authored
30 # send_data(@posts.to_csv, :type => "text/csv; charset=utf-8; header=present", :filename => filename)
f0e678e
wenke authored
31 #}
6b5e79d update readme file
wenke authored
32 end
33 end
34 end
35
36
37 == Install
38
d345a72 update documentation
wenke authored
39 gem install to_csv-rails
40
41 gem 'to_csv-rails'
42 bundle install
6b5e79d update readme file
wenke authored
43
94636e3 @liangwenke update document
authored
44 git clone http://github.com/liangwenke/to_csv-rails.git
6b5e79d update readme file
wenke authored
45
c1ee4ef update readme file
wenke authored
46 == Note
47
94636e3 @liangwenke update document
authored
48 Copyright (c) 2010 liangwenke.com@gmail.com, released under the MIT license
Something went wrong with that request. Please try again.