https://github.com/fny/csv_importable
https://github.com/fny/csv_importable
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/fny/csv_importable
- Owner: fny
- License: mit
- Created: 2014-04-28T23:22:07.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-29T03:46:31.000Z (almost 12 years ago)
- Last Synced: 2025-03-06T00:02:22.778Z (over 1 year ago)
- Language: Ruby
- Size: 156 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CsvImportable
Import CSVs with ActiveModel goodness.
## Installation
Add this line to your application's Gemfile:
gem 'csv_importable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install csv_importable
## Usage
```ruby
class Student < ActiveRecord::Base
include CsvImportable
end
Student.import_csv('filename') # Defaults to using a transaction
Student.import_csv('filename', transaction: false) # Much slower
require 'active-import'
Student.import_csv('filename') # Uses ActiveImport by default if you're using it
csv_import = Student.import_csv('path/to/file')
csv_import.errors # => Gives you an ActiveModel::Errors object
# You can also create play with your own imports without saving:
import = CsvImportable::CsvImport.new(Student, 'path/to/file')
import.valid? # => true
import.executed? # => false
import.save # => true
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request