org.jruby.exceptions.RaiseException: (NameError) uninitialized constant

1.3k Views Asked by At

I'm getting the following error from a JRuby wrapping of the ActiveMerchant library:

org.jruby.exceptions.RaiseException: (NameError) uninitialized constant ActiveMerchant::Billing::SecurePayAuGateway
    at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:3345)
    at org.jruby.RubyModule.const_get(org/jruby/RubyModule.java:3290)
    at RUBY.createGateway(classpath:/scripts/main.rb:79)

The code initiating it is:

gateway = ActiveMerchant::Billing::const_get(name).new(options)

I think this is happening because there is some dynamic loading of the gateways happening in gateways.rb:

module ActiveMerchant
    module Billing
        load_path = Pathname.new(__FILE__ + '/../../..')
        Dir[File.dirname(__FILE__) + '/gateways/**/*.rb'].each do |filename|
            gateway_name      = File.basename(filename, '.rb')
            gateway_classname = "#{gateway_name}_gateway".camelize
            gateway_filename  = Pathname.new(filename).relative_path_from(load_path).sub_ext('')

            autoload(gateway_classname, gateway_filename)
        end
    end
end

This works during unit tests because the Ruby files are real files in my target directory. However in the final application, the Ruby files are contained within a Jar which is in a Jar.

Anyone know why this is happening and how to get it to work?

1

There are 1 best solutions below

1
Mark On

Which gateway are you trying to teach? From Active Merchant's github there is no

ActiveMerchant::Billing::SecurePayAuGateway

But there is a

ActiveMerchant::Billing::SecurePayGateway

And a

ActiveMerchant::Billing::SecurePayTechGateway

To test, instead of

gateway = ActiveMerchant::Billing::const_get(name).new(options)

Try

gateway = ActiveMerchant::Billing::SecurePayGateway

If this works, you know the problem is your gateway = method and you can fix this accordingly