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

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.

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