在我的开发机器上,我使用端口10524.所以我用这种方式启动服务器:
rails s -p 10524
有没有办法将默认端口更改为10524,这样我就不必每次启动服务器时都附加端口?
在我的开发机器上,我使用端口10524.所以我用这种方式启动服务器:
rails s -p 10524
有没有办法将默认端口更改为10524,这样我就不必每次启动服务器时都附加端口?
首先,不要在你的Ruby 路径中编辑任何东西!它会影响所有的项目,你以后会有很多问题...
在项目中,按以下方式编辑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__)
# THIS IS NEW:
require "rails/commands/server"
module Rails
class Server
def default_options
super.merge({
:Port => 10524,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru")
})
end
end
end
# END OF CHANGE
require 'rails/commands'
原理很简单——你是在给服务器运行程序打补丁——所以它只会影响一个项目.
UPDATE:是的,我知道bash脚本有一个更简单的解决方案,它包含:
#!/bin/bash
rails server -p 10524
但是这个解决方案有一个严重的缺点——它非常无聊.