Git Product home page Git Product logo

render_csv's Introduction

render_csv

Build Status Gem Version Code Climate Dependency Status

Rails CSV renderer for ActiveRecord collections

Project Status - May 2015

I am no longer maintaining this project. I have not been able to get it working predictably in newer versions of Rails or in production environments. If you want to add CSV rendering support to your Rails application, I do not recommend installing this gem.

Rails & Ruby Versions Supported

Rails: 3.0.x - 4.0.x

Ruby: 1.9.3, 2.0.0 and 2.1.0

Installation

The gem is hosted at rubygems.org

What is it?

The CSV renderer allows you to render any collection as CSV data.

class LocationsController < ApplicationController
  def index
    @locations = Location.all

    respond_to do |format|
      format.csv  { render csv: @locations }
    end
  end
end

Will render a CSV file similar to:

nameaddresscitystatezipcreated_atupdated_at
Pete's House555 House LnBurlingtonVT054012011-07-26 03:12:44 UTC2011-07-26 03:12:44 UTC
Sebastians's House123 Pup StBurlingtonVT054012011-07-26 03:30:44 UTC2011-07-26 03:30:44 UTC
Someone Else999 Herp DerpBurlingtonVT054012011-07-26 03:30:44 UTC2011-07-26 03:30:44 UTC

Usage Options

There are a few options you can use to customize which columns are included in the CSV file

Exclude columns

respond_to do |format|
  format.csv  { render csv: @locations, except: [:id] }
end

Limit columns

respond_to do |format|
  format.csv  { render csv: @locations, only: [:address, :zip] }
end

Add methods as columns

respond_to do |format|
  format.csv  { render csv: @locations, add_methods: [:method1, :method2] }
end

Add methods as columns and exclude columns

respond_to do |format|
  format.csv  { render csv: @locations, except: [:id], add_methods: [:method1, :method2] }
end

Copyright

Copyright © 2011-2014 Peter Brown. See LICENSE.txt for further details.

render_csv's People

Contributors

beerlington avatar ravinggenius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.