By default, the interface allows us to create records one by one. This can be inefficient if we have a lot of data that we need to save or we want to use data from another application. It’s possible to enable CSV importation in the application.
We’ll use the active_admin_importable
gem for this. In your Gemfile add:
gem 'active_admin_importable'
And then execute bundle install
.
To enable CSV import on the Author page, in app/admin/author.rb
add the following.
active_admin_importable
An Import Authors
button will have appeared at the top right corner of the page. Click on it and browse your local file system for the csv file you want to import. The file should have a header row corresponding with your model attributes. You don’t have to include all columns, as default values will be inserted for columns you leave out.
I created a CSV file with the following two records and imported it.
First name,Last name Jane,Doe
John,Doe
转自:http://www.sitepoint.com/easy-admin-interfaces-active-admin-rails/