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_initializeに変更する必要があり、ApplicationName::Application.config.after_initialize動作するはずです。

于 2013-04-02T09:45:38.547 に答える