【问题标题】:Config settings for active_merchant to be compatible with a Rails 3 app配置 active_merchant 以与 Rails 3 应用程序兼容
【发布时间】:2011-11-03 22:50:11
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails-3 activemerchant


    【解决方案1】:

    看起来您只需要删除 config.after_initialize do 块——之后应该可以正常初始化。

    【讨论】:

      【解决方案2】:

      您可以将此代码放在您的环境文件中,即 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
      

      【讨论】:

      • config/environments/&lt;environment&gt;.rb 文件中添加此代码是rails 2 的事情,并且与rails 3 不完全兼容。因此在升级rails 2.3 应用程序时在其他地方遇到了问题。 Rails 3 的方法是将所有这些配置放在一个初始化文件中。
      【解决方案3】:

      您需要将config.after_initialize 更改为ApplicationName::Application.config.after_initialize,它应该可以工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-14
        • 2022-10-05
        • 2011-03-27
        • 2012-01-23
        相关资源
        最近更新 更多