配置active_merchant的设置以与Rails 3应用程序兼容

时间:2011-08-25 18:23:55

标签: ruby-on-rails-3 activemerchant

我正在关注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)

3 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分: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

答案 2 :(得分:0)

您需要将config.after_initialize更改为ApplicationName::Application.config.after_initialize,它应该正常运行。