active_merchant 的配置设置与 Rails 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)
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::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
The following renders an error:
config/initializers/active_merchant.rb:2:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来你只需要摆脱 config.after_initialize do 块 - 之后应该可以正常初始化。
Looks like you just need to get rid of the
config.after_initialize do
block -- should initialize fine after that.您可以将此代码放入您的环境文件中,即 config/environments/development.rb, production.rb 等只需使用
You can put this code in your environments file i.e config/environments/development.rb, production.rb , etc Just use
您需要将 config.after_initialize 更改为 ApplicationName::Application.config.after_initialize ,它应该可以正常工作。
You need to change
config.after_initialize
toApplicationName::Application.config.after_initialize
and it should be working.