Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 1.24 KB

README.rdoc

File metadata and controls

54 lines (33 loc) · 1.24 KB

Description

This gem adds an import-action in every controller you like to be able to handle csv-Imports. It includes the complete workflow: Csv-Upload, auto-matching and review, importing data into model.

Requirements

Rails 3 & Ruby 1.8.7

In principle it will also work with Ruby 1.9, whereas changes has to be made as FasterCSV is already integrated named as CSV.

Installation

Gemfile:

gem 'csv_mapper', :git => git://github.com/masche842/csv_mapper.git

Set up a new route to point to the import action (get & post will be needed!):

routes.rb

resources :myresource do
  get 'import', :on => :collection
  post 'import', :on => :collection
end

Include it in your Controller:

require 'csv_mapper'
include CsvMapper::ControllerActions

Set up the fields to map to:

csv_mapper_config(
  :mapping => {
    "Firstname" => :firstname,
    "Lastname"  =>  :lastname
  }
)

See also the implementation in spec/dummy!

Usage

call /myresources/import!

Thanks

This gem is heavily based on Andrew Timberlake’s map-fields-gem (github.com/internuity/map-fields). Nevertheless I didn’t fork it, because the changes are fundamental.

License

MIT License. Copyright 2011 magiclabs* (magiclabs.de)