activerecord-import gem NoMethodError: undefined method 'import'
Asked Answered
S

2

7

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

Starfish answered 29/8, 2012 at 23:18 Comment(3)
are you running it in your console?Attainable
yes, I was running it in my consoleStarfish
If you added the gem to Gemfile and installed after starting your rails console, you have to restart the consoleJalopy
A
3

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.

Attainable answered 29/8, 2012 at 23:56 Comment(4)
Well, I was trying it in the Rails console (not just irb) so I shouldn't have to require them. But I've tried that as well and no luck. Now, I'm trying it directly in the rails app and getting the same NoMethodError. I've added the require methods in my model and in that case I get cannot load such file -- activerecord-importStarfish
Your logic holds only if you've that gem included in your gemfile. Do you have it in your gemfile?Attainable
yep, it's definitely in my gemfile. I have no idea what the issue could be.Starfish
works just fine for me, can you explain your process step by step?Attainable
A
0

I ran into the same thing; turns out that for me at least I had the gem included within a test block in the gemfile. make sure that when you include it it's not just limited to one app environment in the gem file.

Ashok answered 9/2, 2022 at 22:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.