Skip to content

Repository files navigation

ActiveAdminImport

Travis Build Coverage StatusCode Climate Gem Version License

The most fastest and efficient CSV import for Active Admin with support of validations, bulk inserts and encodings handling.

For more about ActiveAdminImport installation and usage, check Documentation website and Wiki pages for some specific cases and caveats.

Installation

Add this line to your application's Gemfile:

gem"active_admin_import"

or

gem"active_admin_import",github: "activeadmin-plugins/active_admin_import"

And then execute:

$ bundle

Features

  • Replacements/Updates support
  • Encoding handling
  • CSV options
  • Ability to describe/change CSV headers
  • Bulk import (activerecord-import)
  • Callbacks
  • Zip files
  • and more...

Basic usage

ActiveAdmin.registerPostactive_admin_importoptionsend

Options

ToolDescription
:backresource action to redirect after processing
:csv_optionshash with column separator, row separator, etc
:validatebool (true by default), perform validations or not
:batch_transactionbool (false by default), if transaction is used when batch importing and works when :validate is set to true
:batch_sizeinteger value of max record count inserted by 1 query/transaction
:before_importproc for before import action, hook called with importer object
:after_importproc for after import action, hook called with importer object
:before_batch_importproc for before each batch action, called with importer object
:after_batch_importproc for after each batch action, called with importer object
:on_duplicate_key_updatean Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE or Postgres 9.5+/SQLite 3.24.0+ ON CONFLICT DO UPDATE ability
:on_duplicate_key_ignorebool, tells activerecord-import to use MySQL's INSERT IGNORE or Postgres 9.5+ ON CONFLICT DO NOTHING or SQLite's INSERT OR IGNORE ability
:ignorebool, alias for on_duplicate_key_ignore
:timestampsbool, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
:templatecustom template rendering
:template_objectobject passing to view
:resource_classresource class name
:resource_labelresource label value
:plural_resource_labelpluralized resource label value (default config.plural_resource_label)
:error_limitLimit the number of errors reported (default 5, set to nil for all)
:headers_rewriteshash with key (csv header) - value (db column name) rows mapping
:ifControls whether the 'Import' button is displayed. It supports a proc to be evaluated into a boolean value within the activeadmin render context.

Wiki

Check various examples

Dependencies

ToolDescription
rchardetCharacter encoding auto-detection in Ruby. As smart as your browser. Open source.
activerecord-importPowerful library for bulk inserting data using ActiveRecord.

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 new Pull Request

About

📎 active_admin_import is based on activerecord-import gem - the most efficient way to import for ActiveAdmin

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages