Rails 3.0.x 有没有办法默认使用 Thin?
我基本上为我的开发/测试环境中的每个应用程序运行瘦网络服务器。当我将 Mongrel 与 Rails 2.x 结合使用时,我只需输入 script/server
即可让它运行我选择的 Web 服务器。但对于 Rails 3,我每次都必须指定 Thin。有没有一种方法只需输入 rails s
而不是 rails s Thin
即可在我的 Rails 应用程序上运行 Thin?
I run the Thin webserver for basically every app in my dev/test environments. When I used Mongrel with Rails 2.x, all I had to type was script/server
to get it to run the webserver I choose. But with Rails 3, I have to specify Thin every time. Is there a way to get Thin running on my Rails apps by just typing rails s
instead of rails s thin
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,可以做到这一点。
Rails s 命令在一天结束时的工作方式是通过 Rack 并让它选择服务器。默认情况下,Rack 处理程序将尝试使用
mongrel
,如果找不到 mongrel,它将使用webrick
。我们所要做的就是稍微修补处理程序。我们需要将补丁插入到rails脚本本身中。这就是您要做的,打开您的script/rails
文件。默认情况下,它应该如下所示:我们在
require 'rails/commands'
行之前插入补丁。我们的新文件应如下所示:请注意,它现在将尝试 Mongrel,如果出现错误,请尝试 Thin,然后才使用 Webrick。现在,当您输入
rails s
时,我们就会得到我们想要的行为。Yeah it's possible to do this.
The way the
rails s
command works at the end of the day is by falling through to Rack and letting it pick the server. By default the Rack handler will try to usemongrel
and if it can't find mongrel it will go withwebrick
. All we have to do is patch the handler slightly. We'll need to insert our patch into therails
script itself. Here is what you do, crack open yourscript/rails
file. By default it should look like this:We insert our patch right before the
require 'rails/commands'
line. Our new file should look like this:Notice that it will now try Mongrel and if there is an error try for Thin and only then go with Webrick. Now when you type
rails s
we get the behaviour we're after.从 Rails 3.2rc2 开始,当 Gemfile 中存在
gem 'thin'
时,thin 现在默认在调用rails server
时运行!感谢此拉取请求: https://github.com/rack/rack/commit/b487f02b13f42c5933aa42193ed4e1c0b90382d7对我来说效果很好。
As of Rails 3.2rc2, thin is now run by default on invoking
rails server
whengem 'thin'
is in your Gemfile! Thanks to this pull request: https://github.com/rack/rack/commit/b487f02b13f42c5933aa42193ed4e1c0b90382d7Works great for me.
在 script/rails 中,以下内容也有效:
In
script/rails
the following works as well:只需安装 Thin,cd 到您的应用程序所在的目录并运行 Thin Start。在这里完美运作。 :)
您可以使用 http://www.softiesonrails。 com/2008/4/27/using-thin-instead-of-mongrel 根据需要进行更改。 (我用的就是这个)
Simply install thin, cd to the directory that your app is in and run thin start. Works perfectly here. :)
You can use http://www.softiesonrails.com/2008/4/27/using-thin-instead-of-mongrel to change as needed. (Its the one I used)