Search code examples
ruby-on-rails-3activemerchant

Config settings for active_merchant to be compatible with a Rails 3 app


I'm following http://railscasts.com/episodes/145-integrating-active-merchant

How do I set the configuration settings to be compatible with a Rails 3 app.

I tried putting the following in config/initializers/active_merchant.rb

if Rails.env == 'development'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
      :login     => 'seller12341234zxcv.foobar.com',
      :password  => 'pasword',
      :signature => 'abc123'
    )
  end
elsif Rails.env == 'test'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::BogusGateway.new
  end
elsif Rails.env == 'production'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
      :login     => 'seller12341234zxcv.foobar.com',
      :password  => 'pasword',
      :signature => 'abc123'
    )
  end
end

The following renders an error:

config/initializers/active_merchant.rb:2:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)

Solution

  • Looks like you just need to get rid of the config.after_initialize do block -- should initialize fine after that.