0

Currently confused on configuring my application. I'm currently trying to initialize a new object in config/development.rb

following this sample app tutorial https://www.wepay.com/developer/resources/wefarm-tutorial

My problem is I'm building the application the modular way. where everything sits in engines. The wepay gem is currently installed within the core engine of the application. I'm confused on itializing the new WePay object.

I keep getting the error uninitialized constant Wepay

can someone maybe help to see what I'm doing wrong, am I missing a step since my application is being built within engines instead of Monolithic ?

Any thoughts or help would be great

  • Have you ensured that its not just a typo? `WePay` and `Wepay` are not the same. – max Jan 26 '16 at 13:26
  • Also if you want to initialize something in an engine you would place it in an initializer - not `/config/development.rb`. – max Jan 26 '16 at 13:28
  • @max I'm sure it's not the issue of a typo. – Leafshinobi32 Jan 26 '16 at 22:28
  • @max I think the issue is that I didn't place it into the engine's initializer. Within the WePay docs they didn't specialize creating a new file so how would I go about making a initializer file for this . Sorry I'm a noob to rails especially dealing with engines. – Leafshinobi32 Jan 26 '16 at 22:30

1 Answers1

0

If you wish to use an initializer - code that should run before the engine is loaded - the place for it is the config/initializers folder.

http://guides.rubyonrails.org/engines.html

Rails will require every file in the config/initializers directory as part of the initialization process - when you mount an engine rails will also look in the engines config/initializers directory.

# config/initializers/we_pay.rb
# Note that globals are not thread safe. 
$wepay = WePay::Client.new(
  ENV['WEPAY_CLIENT_ID'],
  ENV['WEPAY_CLIENT_SECRET'],
  true
)

See also:

max
  • 96,212
  • 14
  • 104
  • 165
  • Rail noob here sorry what do you mean by the globals are not thread safe, in the application case this initializer would be used to accept payments so does that mean it will be vulnerable for hacks? would it be safer to simply just tale the wepay gem out of the individual engine and run it into the empty host app @max Thank you for your help – Leafshinobi32 Jan 27 '16 at 18:17