diff options
Diffstat (limited to 'railties/lib/rails/commands.rb')
-rw-r--r-- | railties/lib/rails/commands.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 60a93c9848..02ccdf8060 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -11,7 +11,21 @@ command = ARGV.shift command = aliases[command] || command case command -when 'generate', 'destroy', 'plugin', 'benchmarker', 'profiler' +when 'generate', 'destroy', 'plugin' + if command == 'plugin' && ARGV.first == 'new' + require "rails/commands/plugin_new" + else + require APP_PATH + Rails.application.require_environment! + + if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH) + Rails.application = engine + end + + require "rails/commands/#{command}" + end + +when 'benchmarker', 'profiler' require APP_PATH Rails.application.require_environment! require "rails/commands/#{command}" @@ -23,8 +37,15 @@ when 'console' Rails::Console.start(Rails.application) when 'server' + # Change to the application's path if there is no config.ru file in current dir. + # This allows us to run script/rails server from other directories, but still get + # the main config.ru and properly set the tmp directory. + Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru")) + require 'rails/commands/server' Rails::Server.new.tap { |server| + # We need to require application after the server sets environment, + # otherwise the --environment option given to the server won't propagate. require APP_PATH Dir.chdir(Rails.application.root) server.start @@ -41,6 +62,7 @@ when 'application', 'runner' when 'new' puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n" puts "Type 'rails' for help." + exit(1) when '--version', '-v' ARGV.unshift '--version' @@ -70,4 +92,5 @@ In addition to those, there are: All commands can be run with -h for more information. EOT + exit(1) end |