Initializing object within devolopment.rb envirorment using gem within rails mountable engine

我怕爱的太早我们不能终老 提交于 2019-12-12 03:33:01

问题


Completely lost.

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

which seems like a simple tutorial to follow except I'm building it inside a rails engine. I'm currently attempting to follow the tutorial and initialize the new object.

initialize a new WePay object. add these variables to config/development.rb:

wefarm / config / environments / development.rb

App specific information

CLIENT_ID = 32636
CLIENT_SECRET = "180c800c62"
USE_STAGE = true
WEPAY = WePay.new(CLIENT_ID, CLIENT_SECRET, USE_STAGE)

The issue I think I'm having is the gem is within my core engine allong with user's and the rest of the application and I'm adding these lines of code into the empty shell app. How would I make sure my engine uses this in development I'm also assuming I will come across this issue again when I'm set for production.

In another question a user specified I'm putting this code into the wrong area if I'm using an engine it should be in the initializer folder, but within the documents they just specify putting the code within the config/environments file so where/how exactly do I translate this over to an engine. If it goes into the initializer folder how would I make that file to just include the code specified?

Any help would be amazingly helpful.

Ps. The client Id and secret our just test information


回答1:


In Rails 4 engine, define the app specific information in secrets.yml

  1. Specifying secrete keys and ids according to environment will solve environment related configuration for keys. Example : development:

    CLIENT_ID: 123

  2. Make engine configurable

Example in config/initializer/wefarm.rb

Weform.CLIENT_ID =  Rails.application.secrets.CLIENT_ID 
  1. In lib/engine.rb (engine)

    mattr_accessor :CLIENT_ID

Now you can access client_id in engine as WeForm.CLIENT_ID

For more information Rails Engine



来源:https://stackoverflow.com/questions/35025931/initializing-object-within-devolopment-rb-envirorment-using-gem-within-rails-mou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!