aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorSimo Niemelä <simo.niemela@gmail.com>2010-02-09 23:21:11 +0200
committerJosé Valim <jose.valim@gmail.com>2010-02-10 08:14:02 +0100
commitcafe882d12d767f510d6b8ad283f49a1c02e82ad (patch)
tree7303f558b6518393254f3dcc9533e44bccedb80e /railties
parentf337ebc308b95671ba8620a0cc56f75c4fb11e15 (diff)
downloadrails-cafe882d12d767f510d6b8ad283f49a1c02e82ad.tar.gz
rails-cafe882d12d767f510d6b8ad283f49a1c02e82ad.tar.bz2
rails-cafe882d12d767f510d6b8ad283f49a1c02e82ad.zip
Fix server environment [#3877 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands.rb7
-rw-r--r--railties/lib/rails/commands/server.rb15
2 files changed, 16 insertions, 6 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 991d2a0205..6972e25b29 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -33,10 +33,13 @@ when 'c', 'console'
require APP_PATH
Rails::Console.start(Rails::Application)
when 's', 'server'
- require APP_PATH
require 'rails/commands/server'
+ # Initialize the server first, so environment options are set
+ server = Rails::Server.new
+ require APP_PATH
+
Dir.chdir(Rails::Application.root)
- Rails::Server.start
+ server.start
when 'db', 'dbconsole'
require 'rails/commands/dbconsole'
require APP_PATH
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 281e4da3d2..c57660c0d1 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -6,8 +6,8 @@ module Rails
class Server < ::Rack::Server
class Options
def parse!(args)
- options = {}
- args = args.dup
+ args, options = args.dup, {}
+
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: rails server [options]"
opts.on("-p", "--port=port", Integer,
@@ -34,13 +34,20 @@ module Rails
end
end
+ def initialize(*)
+ super
+ set_environment
+ end
+
def opt_parser
Options.new
end
- def start
- ENV["RAILS_ENV"] = options[:environment]
+ def set_environment
+ ENV["RAILS_ENV"] ||= options[:environment]
+ end
+ def start
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
puts "=> Call with -d to detach" unless options[:daemonize]