Ruby on Rails:从初始化程序文件运行 rake 任务时出错
我有文件 config/initializers/custom.rb
在该文件中,只有一行:
`rake thinking_sphinx:start`
我认为这应该只是执行该行,就像从命令行键入它一样。 使用这行代码,当我运行“ruby script/server”时,服务器冻结并且不输出任何错误消息。 我错过了什么吗?
谢谢!
I have the file config/initializers/custom.rb
In the file, there is only one line:
`rake thinking_sphinx:start`
I thought this was supposed to just execute the line like when typing it from a command line. With this line of code, when I run "ruby script/server", the server freezes and outputs no error messages. Am I missing something?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
初始化程序会在应用程序加载时加载。 Rake 任务通常会加载您的应用程序。 如果您从初始化程序调用 Rake 任务,您将使您的应用程序陷入循环。
如果您担心忘记在开发中启动 Sphinx,请给自己一点警告:
Initializers load when your application loads. Rake tasks generally load your application. If you call a Rake task from an initializer, you're going to throw your app for a loop.
If you're worried about forgetting to start Sphinx in development, just give yourself a little warning:
我询问如何通过 netbeans 使其在开发模式下启动,但想法是相同的。 赏金仍然开放。
我的猜测是,您无法启动服务器,因为 sphinx 需要它自己的进程,因此它永远不会返回到您的自定义初始值设定项。
I asked about how to get it to start up in dev mode via netbeans but the idea is the same. Bounty is still open.
My guess is that your not getting to the server starting because sphinx needs it's own process so it never returns to your custom initializer.