views:

63

answers:

2

On my development machine, I use port 10524. So I start my server this way :

rails s -p 10524

Is there a way to change the default port to 10524 so I wouldn't have to append the port each time I start the server?

+1  A: 

First option:

Modify railties-3.0.0/lib/rails/commands/server.rb In default_options method change port number:

    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 

Second option: create alias in your shell.

Casual Coder
editing files in your gem path is... well, only for the bravest. It will not survive gem updates, it will not work across more computers, etc. I really would not recommend it
pawien
You are right. Your solution is much better. I didn't know, that I can override it in `script/rails`. Thanks for that.
Casual Coder
+5  A: 

First - do not edit anything in your gem path! It will influence all projects, and you will have a lot problems later...

In your project edit script/rails this way:

#!/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'

The principle is simple - you are monkey-patching the server runner - so it will influence just one project.

UPDATE: Yes, I know that the there is simpler solution with bash script containing:

#!/bin/bash
rails server -p 10524

but this solution has a serious drawback - it is boring as hell.

pawien