gpt4 book ai didi

ruby-on-rails - rails config/environments 'config' 在哪里定义?

转载 作者:数据小太阳 更新时间:2023-10-29 07:35:23 27 4
gpt4 key购买 nike

config/environments/production.rb(和其他环境)中有:

config.eager_load = true

和一大堆其他 config.foobar 调用。但是“配置”从何而来?通常你有这样的东西:

SomeClass.each do | block_variable |
block_variable.some_method
end

但对于神秘的“配置”,情况并非如此,它就像一个未在任何地方声明的 block 变量。打开 Rails 控制台,当我这样做时:

irb(main):001:0> config
NameError: undefined local variable or method `config' for main:Object
Did you mean? conf
from (irb):1
irb(main):002:0>

app.config

的结果相同
irb(main):002:0> app.config
NoMethodError: undefined method `config' for #<ActionDispatch::Integration::Session:0x00007fc898d02808>
from (irb):2

ruby 怎么可能允许调用“config”?

最佳答案

这些类包括 ActiveSupport::Configurable 模块:

https://api.rubyonrails.org/classes/ActiveSupport/Configurable.html

以下是您自己实现此行为的替代方法:

https://robots.thoughtbot.com/mygem-configure-block

关于ruby-on-rails - rails config/environments 'config' 在哪里定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52387146/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com