Skip to content
Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyon
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



activerecord-import is a library for bulk inserting data using ActiveRecord. By default with ActiveRecord, in order to insert multiple records you have to perform individual save operations on each model, like so:

10.times do |i|
  Book.create! :name => "book #{i}"

This may work fine if all you have is 10 records, but if you have hundreds, thousands, or millions of records it can turn into a nightmare. This is where activerecord-import comes into play. Here's the equivalent behaviour using the #import method:

books = []
10.times{ |i| books << => "book #{i}") }
Book.import books

Pretty slick, eh?

Maybe, just maybe you're thinking, why do I have do instantiate ActiveRecord objects? Will that perform validations? What if I don't want validations? What if I want to take advantage of features like MySQL's on duplicate key update? Well, activerecord-import handles all of these cases and more!

For more documentation on the matter you can refer to two places:

  1. activerecord-import github wiki:
  2. the tests in the code base

Upgrading from ar-extensions

This library replaces the ar-extensions library and is compatible with Rails 3. It provides the exact same API for importing data, but it does not include any additional ar-extensions functionality.


This is licensed under the ruby license.


Zach Dennis (


  • Blythe Dunham
  • Gabe da Silveira
  • Henry Work
  • James Herdman
  • Marcus Crafter
  • Thibaud Guillaume-Gentil
  • Mark Van Holstyn
  • Victor Costan
Something went wrong with that request. Please try again.