gpt4 book ai didi

ruby-on-rails - Rails 3.0.x 是否可以默认使用 Thin?

转载 作者:数据小太阳 更新时间:2023-10-29 06:38:42 28 4
gpt4 key购买 nike

我基本上为我的开发/测试环境中的每个应用程序运行瘦网络服务器。当我将 Mongrel 与 Rails 2.x 一起使用时,我只需键入 script/server 即可运行我选择的网络服务器。但是对于 Rails 3,我每次都必须指定 Thin。是否可以通过键入 rails s 而不是 rails s thin 让 Thin 在我的 Rails 应用程序上运行?

最佳答案

是的,这是可能的。

rails s 命令在一天结束时的工作方式是通过 Rack 并让它选择服务器。默认情况下,Rack 处理程序将尝试使用 mongrel,如果找不到 mongrel,它将使用 webrick。我们所要做的就是稍微修补处理程序。我们需要将补丁插入 rails 脚本本身。这是您要做的,打开您的 script/rails 文件。默认情况下它应该是这样的:

#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'

我们在 require 'rails/commands' 行之前插入我们的补丁。我们的新文件应如下所示:

#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rack/handler'
Rack::Handler.class_eval do
def self.default(options = {})
# Guess.
if ENV.include?("PHP_FCGI_CHILDREN")
# We already speak FastCGI
options.delete :File
options.delete :Port

Rack::Handler::FastCGI
elsif ENV.include?("REQUEST_METHOD")
Rack::Handler::CGI
else
begin
Rack::Handler::Mongrel
rescue LoadError
begin
Rack::Handler::Thin
rescue LoadError
Rack::Handler::WEBrick
end
end
end
end
end
require 'rails/commands'

请注意,它现在将尝试 Mongrel,如果出现错误,请尝试 Thin,然后再使用 Webrick。现在,当您键入 rails s 时,我们会得到我们想要的行为。

关于ruby-on-rails - Rails 3.0.x 是否可以默认使用 Thin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4853393/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com