在 development 模式下,如果想监控某些文件变动,自动加载某些文件,在 config/initializers 下创建一个 rb 文件,简单配置如下:
locale_reloader = ActiveSupport::FileUpdateChecker.new(Dir["config/ruby-china.yml"]) do
STDOUT.print "HELLO WORLD"
end
ActionDispatch::Callbacks.to_prepare do
locale_reloader.execute_if_updated
end
鄙人想自动加载某个文件,但是发现这段代码不起作用。有类似经验的,请指点迷津。谢谢。
Provide callbacks to be executed before and after the request dispatch.
It also provides a to_prepare callback, which is performed in all requests in development by only once in production and notification callback for async operations.
所以这个在有请求后才会触发。