我正在尝试使用to_prepare事件来处理新的Rails 3.2.1项目.我放置了以下内容:
Rails.application.config.to_prepare do
puts 'here i am before a request'
end
Run Code Online (Sandbox Code Playgroud)
进入config/initializers下的初始化程序.根据此处的文档,当在开发模式下运行时,此块应该在应用程序的每个请求上运行,并且仅在生产中运行一次.我正在开发模式,这个块不会在每个请求上运行,而是仅在我启动应用程序时运行,而不是再次运行.
以下是我加载应用程序时的输出示例.
rails s
=> Booting WEBrick
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
here i am before a request
[2012-03-02 20:29:46] INFO WEBrick 1.3.1
[2012-03-02 20:29:46] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin11.2.0]
[2012-03-02 20:29:46] INFO WEBrick::HTTPServer#start: pid=37897 port=3000
Run Code Online (Sandbox Code Playgroud)
当我发出后续请求时,不显示字符串'here i is ...',只显示Rails日志的常规输出.我所有的搜索都只提到了文档,似乎告诉我这样做.有什么我可能会失踪的吗?