更改Rails的默认服务器 [英] Change default server for Rails

查看:107
本文介绍了更改Rails的默认服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了杂种gem,因为在极少数情况下我需要在工作站上使用它,现在它是我的默认Rails(2)服务器.我知道我可以在命令行上指定script/server webrick,但是事实是我想让我的系统(或应用程序)默认为webrick,并且仅在指定时使用mongrel.

I installed the mongrel gem because I need it on my workstation for rare occasions, and now it's my default Rails (2) server. 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.

有人知道如何安排吗?

规格:WinXP,Rails 2.3.12,Ruby 1.8.7

Specs: WinXP, Rails 2.3.12, Ruby 1.8.7

推荐答案

好的,这里有一些选择:

Ok here are a few options:

选项一-一次关闭:始终将webrick添加为命令行参数

Option one - One off: Always add webrick as a command line arg

打开脚本/服务器,并在两个要求之间插入一行

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'

选项2-全局:编辑启动rails的commands/server.rb文件

Option two - Global: Edit the commands/server.rb file that launches rails

gem哪个rails->告诉您启动代码在哪里 在lib/commands/server.rb

gem which railties -> tells you where the startup code is Open the file at lib/commands/server.rb

在第45行周围编辑逻辑,以便默认情况下始终启动webrick.

Around line 45 edit the logic so that webrick is always launched by default.

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

选项3-最干净但最复杂的:

Option 3 - Cleanest but most involved:

切换到Bundler并直接管理您的依赖项.这需要做更多的工作,但是您可以在某个时候切换到rails 3,这可能取决于应用程序的生命周期. 这里有一个关于Rails 2.3的教程

Switch to Bundler and manage your dependencies directly. 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. There's a tutorial for rails 2.3 here

这篇关于更改Rails的默认服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆