0.0
No commit activity in last 3 years
No release in over 3 years
Easily add CSV import tools to any ActiveRecord model.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

= 1.4.5
= 3.2.13
>= 0.9.2
 Project Readme

ActiveRecord CSV Importer

What is it?

Man am I ever sick of writing the same code over and over again to import CSV representations of data in my Rails applications. You probably are too. Install ActiveRecord CSV Importer and stop doing it!

Requirements

Ruby: >= 1.9.3

Rails: >= 3.2

Installation

Put it in your Gemfile, as usual, and run bundle install. Easy!

gem 'ar_csv_importer'

Usage

Setting up the class: Let's imagine you have a Merchant class. The class has a title, an address, a URL, and a description. First, add the importer to your class.

class Merchant < ActiveRecord::Base
   has_csv_importer :title, :address, :url, :description
end

Note that the order that you list your attributes should match the order of the fields in your CSV.

Running the import:

Merchant.csv_import('/path/to/csv_file')

If you want to run the import and raise validation errors:

Merchant.csv_import!('/path/to/csv_file')

That's it!