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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 Aug 2008, at 21:46, mveerman <mark-vXf+4/sDwOJBDgjK7y7TUQ@public.gmane.org> wrote:> > 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> Thanks! > Mark > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 Aug 2008, at 21:46, mveerman <m...-vXf+4/sDwOJBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > > > 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 > > > Thanks! > > Mark--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---