3

我正在关注http://railscasts.com/episodes/145-integrating-active-merchant

如何设置配置设置以与 Rails 3 应用程序兼容。

我尝试将以下内容放入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

以下呈现错误:

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

3 回答 3

4

看起来你只需要摆脱config.after_initialize do块 - 之后应该初始化很好。

于 2011-08-25T18:42:48.967 回答
1

您可以将此代码放在您的环境文件中,即 config/environments/development.rb、production.rb 等只需使用

config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test
  ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
   :login     => 'seller12341234zxcv.foobar.com',
   :password  => 'pasword',
   :signature => 'abc123'
  )
end
于 2014-02-18T06:33:39.373 回答
0

您需要更改config.after_initializeApplicationName::Application.config.after_initialize,它应该可以正常工作。

于 2013-04-02T09:45:38.547 回答