From 3022ce4f723075d201d9a20f7bca3537aa76a7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 7 Jan 2010 21:24:50 +0100 Subject: No more hacks to ensure generators are executed inside Rails.root. --- railties/lib/rails/commands/destroy.rb | 2 +- railties/lib/rails/commands/generate.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index f85c17bb94..a2eff377ce 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -7,4 +7,4 @@ if ARGV.size == 0 end name = ARGV.shift -Rails::Generators.invoke name, ARGV, :behavior => :revoke +Rails::Generators.invoke name, ARGV, :behavior => :revoke, :destination_root => Rails.root diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index c5e3ae3529..c1120aad74 100755 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -7,4 +7,4 @@ if ARGV.size == 0 end name = ARGV.shift -Rails::Generators.invoke name, ARGV, :behavior => :invoke +Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root -- cgit v1.2.3 From d2c4a93c6966cb06d6029f9f4dbe5f71a52a02db Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 9 Jan 2010 09:52:16 -0800 Subject: Have to remove the environment name from ARGV or IRB will freak out --- railties/lib/rails/commands/console.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 37eb6d40ea..d154808029 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -25,7 +25,7 @@ module Rails opt.parse!(ARGV) end - if env = ARGV.first + if env = ARGV.pop ENV['RAILS_ENV'] = ENVIRONMENTS.find { |e| e.index(env) } || env end -- cgit v1.2.3 From 8cb594a2e1808cd7d93f3593afed0414016fc56f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 11 Jan 2010 14:01:28 -0800 Subject: Get everyone running on Rails.env and fix the broken environment settings for script/console and script/dbconsole --- railties/lib/rails/commands/console.rb | 11 +++++------ railties/lib/rails/commands/dbconsole.rb | 6 +++++- railties/lib/rails/commands/runner.rb | 1 - railties/lib/rails/commands/server.rb | 7 +++---- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index d154808029..27ac7fd20a 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -4,8 +4,6 @@ require "irb/completion" module Rails class Console - ENVIRONMENTS = %w(production development test) - def self.start(app) new(app).start end @@ -25,10 +23,6 @@ module Rails opt.parse!(ARGV) end - if env = ARGV.pop - ENV['RAILS_ENV'] = ENVIRONMENTS.find { |e| e.index(env) } || env - end - @app.initialize! require "rails/console_app" require "rails/console_sandbox" if options[:sandbox] @@ -54,3 +48,8 @@ module Rails end end end + +# Has to set the RAILS_ENV before config/application is required +if ARGV.first && !ARGV.first.index("-") && env = ARGV.pop # has to pop the env ARGV so IRB doesn't freak + ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env +end diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 77c3404343..b836a17a49 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -34,7 +34,6 @@ module Rails abort opt.to_s unless (0..1).include?(ARGV.size) end - env = ARGV.first || ENV['RAILS_ENV'] || 'development' unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env] abort "No database is configured for the environment '#{env}'" end @@ -97,4 +96,9 @@ module Rails end end end +end + +# Has to set the RAILS_ENV before config/application is required +if ARGV.first && !ARGV.first.index("-") && env = ARGV.first + ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env end \ No newline at end of file diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 0246348c77..4487d2e7b1 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -34,7 +34,6 @@ end ARGV.delete(code_or_file) ENV["RAILS_ENV"] = options[:environment] -RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) begin if code_or_file.nil? diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 09d7207d51..b21ae2a17b 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -38,15 +38,14 @@ module Rails end def start + ENV["RAILS_ENV"] = options[:environment] + puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" - puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}" + puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}" puts "=> Call with -d to detach" unless options[:daemonize] trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] - ENV["RAILS_ENV"] = options[:environment] - RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) - super ensure puts 'Exiting' unless options[:daemonize] -- cgit v1.2.3 From b0994be5bd24559f1362a636b46271de6d6a92d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 10:46:30 +0100 Subject: LogTailer should be invoked after all logs in threads were flushed. --- railties/lib/rails/commands/server.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index b21ae2a17b..851a21c51d 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -46,6 +46,7 @@ module Rails trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] + Rails::Subscriber.tail_log = true unless options[:daemonize] super ensure puts 'Exiting' unless options[:daemonize] @@ -53,15 +54,10 @@ module Rails def middleware middlewares = [] - middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize] middlewares << [Rails::Rack::Debugger] if options[:debugger] Hash.new(middlewares) end - def log_path - "log/#{options[:environment]}.log" - end - def default_options super.merge({ :Port => 3000, -- cgit v1.2.3 From 6487d2871cbd44d769c483f47130e18d53e6e381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 12:15:49 +0100 Subject: Fix an issue where log was not being tailed in the first request. --- railties/lib/rails/commands/server.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 851a21c51d..115499db05 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -46,7 +46,7 @@ module Rails trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] - Rails::Subscriber.tail_log = true unless options[:daemonize] + initialize_log_tailer! unless options[:daemonize] super ensure puts 'Exiting' unless options[:daemonize] @@ -58,6 +58,10 @@ module Rails Hash.new(middlewares) end + def log_path + "log/#{options[:environment]}.log" + end + def default_options super.merge({ :Port => 3000, @@ -67,5 +71,14 @@ module Rails :pid => "tmp/pids/server.pid" }) end + + protected + + # LogTailer should not be used as a middleware since the logging happens + # async in a request and the middleware calls are sync. So we send it + # to subscriber which will be responsible for calling tail! in the log tailer. + def initialize_log_tailer! + Rails::Subscriber.log_tailer = Rails::Rack::LogTailer.new(nil, log_path) + end end end -- cgit v1.2.3 From 488b4c8c5c8e441c0aaaa9d4f71263dd3beacde4 Mon Sep 17 00:00:00 2001 From: Sam Granieri Date: Wed, 13 Jan 2010 18:38:22 -0600 Subject: Make script/dbconsole work again [#3690 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/rails/commands/dbconsole.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index b836a17a49..593e2d8ee3 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -34,8 +34,8 @@ module Rails abort opt.to_s unless (0..1).include?(ARGV.size) end - unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env] - abort "No database is configured for the environment '#{env}'" + unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[Rails.env] + abort "No database is configured for the environment '#{Rails.env}'" end -- cgit v1.2.3