0.0
No commit activity in last 3 years
No release in over 3 years
Download ActiveRecord collection as csv
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
 Project Readme

Collection2csv

Build Status Code Climate security

Collection2csv gem allows you to export a ActiveRecord collection of model objects to csv

Installation

Add this line to your application's Gemfile:

gem 'collection2csv'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install collection2csv

Usage

Use the collection_download helper like any other regular tag helper :

<%= collection_download(@activerecord_collection) %>

eg: <%= collection_download(@users) %>

In order to select a particular columns use column names as follows

<%= collection_download(@activerecord_collection, {columns: ['id','name']}) %>

eg: <%= collection_download(@users, {columns: ['id','name']}) %>

Download link text can be provided as follows

<%= collection_download(@activerecord_collection, {link_text: 'export'}) %>

eg: <%= collection_download(@users, {link_text: 'export'}) %>

Supports Associations

<%= collection_download(@activerecord_collection, {columns: ['id','name'], associations: {association_name: ['id','name']}}) %>

eg: <%= collection_download(@users, {columns: ['id','name'], associations: {book: ['name', 'author']}}) %>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ethirajsrinivasan/collection2csv.

License

The gem is available as open source under the terms of the MIT License.