Uninitialized initializer constant

穿精又带淫゛_ 提交于 2019-12-11 12:08:09

问题


I created a settings.rb file under the initializers folder containing values I need initialized once the application starts. However, on running rails s I get a "Uninitialized contant Settings(NameError)

Settings.rb

Settings.defaults[:single_phase] = 500
Settings.defaults[:three_phase]  = 300

I created the migration to accompany it already and the view.

Where is the problem?


回答1:


In your config/application_settings.rb

development:
  single_phase: 200

and use it anywhere in your app

APP_SETTINGS['single_phase']

which returns 200




回答2:


At the time initializers run they do not have access to the model (is it a model?).

If it isn't a model, you can do the following:

SETTINGS = {}
SETTINGS[:single_phase] = 500

However I feel like the figaro gem might be helpful for what you are trying to do.

You can also add arbitrary settings in the application.rb and environment files.



来源:https://stackoverflow.com/questions/15609169/uninitialized-initializer-constant

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