Skip to content

Epictetus/csv_rails

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CsvRails

CsvRails provides a simple way of download csv in Rails 3.

Install

To use CsvRails simply add the line

gem 'csv_rails'

to your Gemfile and then run

bundle install

Example

class UsersController < ApplicationController
  def index
    @users = User.all

    respond_to do |format|
      format.html { @users = @users.all }
      format.json { render json: @users }
      format.csv{ render csv: @users, :fields => [:id, :name, :age], :encoding => 'SJIS' }
    end
  end

Usage

If you want formatted created_at in the csv you should write like this

class User < ActiveRecord::Base
  def created_at_as_csv
    created_at.strftime("%F %H:%M")
  end
end

Copyright © 2012 yalab, released under the MIT license

About

A rails plugin for download csv.

Resources

License

Stars

Watchers

Forks

Packages

No packages published