开发者

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::BogusGatewa开发者_如何学编程y.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)


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


You can put this code in your environments file i.e config/environments/development.rb, production.rb , etc Just use

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


You need to change config.after_initialize to ApplicationName::Application.config.after_initialize and it should be working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜