问题描述
我在initializers文件夹下创建了一个settings.rb文件,其中包含我需要在应用程序启动时初始化的值。然而,在运行轨道上,我得到了一个未初始化的内存设置(NameError)
Settings.rb
Settings.defaults [:single_phase] = 500
Settings.defaults [:three_phase] = 300
我已经创建了迁移,并且已经和视图一起使用了。
问题在哪里?
设置= {}
设置[ :single_phase] = 500
但是我觉得像 gem可能对您正在尝试做的事有帮助。
您还可以添加任意设置在application.rb和环境文件中。
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?
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.
这篇关于未初始化的初始化器常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!