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

我试过了:

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代码? - 代码日志