gpt4 book ai didi

ruby-on-rails - Rails 服务器启动后如何运行我的 ruby​​ 代码?

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

我试过:

after_initialize do
#code
end

但是:(文档)

Some parts of your application, notably observers and routing, are not yet set up at the point where the after_initialize block is called.

我的代码中需要路由和记录器

有什么想法吗?

最佳答案

参见 http://guides.rubyonrails.org/configuring.html 的第 3.1 节

我相信你会把这段代码放在 config/application.rb 中

config.after_initialize do
# ....
end

# config.after_initialize takes a block which will be run after Rails has finished initializing the application.
# That includes the initialization of the framework itself

还有 http://guides.rubyonrails.org/initialization.html

关于ruby-on-rails - Rails 服务器启动后如何运行我的 ruby​​ 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8543904/

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