Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activerecord-import gem NoMethodError: undefined method 'import'

I'm trying to use the activerecord-import gem and I've followed the directions on the wiki to a tee but I'm getting a NoMethodError: undefined method 'import' for #<Class:0x8b009b0>. Here's my code (basically the same as the example from the wiki)

    class ExampleCode
      def self.testing
        orders = []
        10.times do |i|
          orders << Order.new(:raw_data => "order #{i}")
        end

        Order.import orders

      end
    end

I call the method like so:

ExampleCode.testing

I've tried on windows, linux, with a sqlite database, a mysql database and still no luck. And I'm certain I have the gem installed:

actionmailer (3.2.6, 3.2.3, 3.2.1, 3.2.0)
actionpack (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activemodel (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord-import (0.2.10)
activerecord-oracle_enhanced-adapter (1.4.1)
activerecord-sqlserver-adapter (3.2.1)....

I even tried to use require (which shouldn't be necessary when the gem is installed. I haven't seen this come up anywhere else so I fear I must to missing something very obvious

like image 354
yiinewbie Avatar asked Aug 29 '12 23:08

yiinewbie


1 Answers

You'll have to import active_record and activerecord-import

i.e.

require active_record
require activerecord-import

(as mentioned in the wiki)

The reason being, ruby won't know about it unless you explicitly import those libraries. In case of a rails project, rails imports all gems mentioned in the Gemfile for you.

like image 108
rb512 Avatar answered Sep 28 '22 03:09

rb512