未初始化的初始化器常量 [英] Uninitialized initializer constant

查看:112
本文介绍了未初始化的初始化器常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在initializers文件夹下创建了一个settings.rb文件,其中包含我需要在应用程序启动时初始化的值。然而,在运行轨道上,我得到了一个未初始化的内存设置(NameError)

Settings.rb

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

我已经创建了迁移,并且已经和视图一起使用了。



问题在哪里?
<在初始化器运行的时候,他们无法访问模型(是模型吗?)。

 设置= {} 
设置[ :single_phase] = 500

但是我觉得像 figaro 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.

这篇关于未初始化的初始化器常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆