Config.after_initialize and development mode

Hi,

I’m using activemerchant and setting up a class variable using
config.after_initialize. It works great for the first request, but
then the variable is nil.

config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
OrderTransaction.gateway =
ActiveMerchant::Billing::PaypalGateway.new(…)
end

I’m assuming this is is due to the model reloading after each request
in development mode, right? When that happens OrderTransaction.gateway
is nilified.

Is there a way to prevent a model from being reloaded in development
mode, and is this the best way to handle the problem.

Thanks!
Mark

On 24 Aug 2008, at 21:46, mveerman [email protected] wrote:

ActiveMerchant::Billing::PaypalGateway.new(…)
end

I’m assuming this is is due to the model reloading after each request
in development mode, right? When that happens OrderTransaction.gateway
is nilified.

Sounds plausible

Is there a way to prevent a model from being reloaded in development
mode, and is this the best way to handle the problem.

Add the model file to Dependencies.load_once_paths (may cause problems
if that’s a model with associations to other models etc…) or use
config.to_prepare (which executes before each request us dispatched)

Fred

That worked perfectly!

I decided to use config.to_prepare in environments/development.rb
like:
config.to_prepare do
ActiveMerchant::Billing::Base.mode = :test
OrderTransaction.gateway =
ActiveMerchant::Billing::PaypalGateway.new(…)
end

and left config.after_initialize in environments/production.rb
I haven’t tested the production environment yet, but I’m assuming I
won’t run into the same problem.

Thanks for the help,

Mark

On Aug 24, 5:09 pm, Frederick C. [email protected]