2011-08-25 26 views
3

我下面http://railscasts.com/episodes/145-integrating-active-merchant爲active_merchant配置設置,以兼容一個Rails 3應用程序

如何設置的配置設置爲與一個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

看起來像你只需要擺脫config.after_initialize do塊 - 應後初始化罰款。

0

您需要將config.after_initialize更改爲ApplicationName::Application.config.after_initialize並且它應該正常工作。

1

你可以把這段代碼在你的環境中的文件,即配置/環境/ 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 
+0

在'配置/環境中添加該代碼/ .rb'文件是一個軌道2的事情,並不完全兼容軌道3.因爲這個原因升級軌道2.3應用程序時遇到問題。 Rails 3的方法是將所有這些配置放入初始化文件中。 –

相關問題