Provides a controller action and views for uploading, mapping and importing data from a csv
Ruby JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app/views/controller_actions
lib
spec
.gitignore
.rspec
Gemfile
MIT-LICENSE
README.rdoc
Rakefile
csv_mapper.gemspec

README.rdoc

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)