简体   繁体   English

更改Rails的默认服务器

[英]Change default server for Rails

I installed the mongrel gem because I need it on my workstation for rare occasions, and now it's my default Rails (2) server. 我安装了杂种gem,因为在极少数情况下我需要在工作站上使用它,现在它是我的默认Rails(2)服务器。 I know I could specify script/server webrick on the command line, but the fact is that I'd like to have my system (or app) default to webrick, and only use mongrel when specified. 我知道我可以在命令行上指定script/server webrick ,但事实是我想让我的系统(或应用程序)默认为webrick,并且仅在指定时使用mongrel。

Anybody know how to arrange that? 有人知道如何安排吗?

Specs: WinXP, Rails 2.3.12, Ruby 1.8.7 规格:WinXP,Rails 2.3.12,Ruby 1.8.7

Ok here are a few options: 好的,这里有一些选择:

Option one - One off: Always add webrick as a command line arg 选项一-一次关闭:始终将webrick添加为命令行参数

Open script/server and insert a line between the two requires 打开脚本/服务器,并在两者之间插入一行

#!/usr/bin/env ruby
require File.expand_path('../../config/boot',  __FILE__)
ARGV.unshift "webrick"
require 'commands/server'

Option two - Global: Edit the commands/server.rb file that launches rails 选项2-全局:编辑启动rails的commands / server.rb文件

gem which railties -> tells you where the startup code is Open the file at lib/commands/server.rb gem哪个railties->告诉您启动代码在哪里打开lib / commands / server.rb中的文件

Around line 45 edit the logic so that webrick is always launched by default. 在第45行周围,编辑逻辑,以便默认情况下始终启动webrick。

server = Rack::Handler.get(ARGV.first) rescue nil
unless server
  begin
    server = Rack::Handler::WEBrick # was Mongrel
  rescue LoadError => e
    server = Rack::Handler::WEBrick
  end
end

Option 3 - Cleanest but most involved: 选项3-最干净但涉及最多的:

Switch to Bundler and manage your dependencies directly. 切换到Bundler并直接管理您的依赖项。 This is more work but positions you for switching to rails 3 at some point which might be nice depending on the life cycle of the application. 这是更多的工作,但是您可以在某个时候切换到rails 3,这可能取决于应用程序的生命周期。 There's a tutorial for rails 2.3 here 这里有关于Rails 2.3教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM