Created
June 8, 2010 12:24
-
-
Save FooBarWidget/429944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c91acde4040362f545e51d7cfcf600155354a803 Mon Sep 17 00:00:00 2001 | |
From: Hongli Lai (Phusion) <[email protected]> | |
Date: Tue, 8 Jun 2010 13:22:25 +0200 | |
Subject: [PATCH] Fix unicorn_rails compatibility with the latest Rails 3 code. | |
--- | |
bin/unicorn_rails | 23 +++++++++++++++++++++-- | |
1 files changed, 21 insertions(+), 2 deletions(-) | |
diff --git a/bin/unicorn_rails b/bin/unicorn_rails | |
index 45a9b11..4faaed3 100755 | |
--- a/bin/unicorn_rails | |
+++ b/bin/unicorn_rails | |
@@ -109,6 +109,25 @@ end | |
ru = ARGV[0] || (File.exist?('config.ru') ? 'config.ru' : nil) | |
+def rails_dispatcher | |
+ if ::Rails::VERSION::MAJOR >= 3 && ::File.exist?('config/application.rb') | |
+ ::File.read('config/application.rb') =~ /^module (.+)$/ | |
+ if $1 | |
+ app_module = Object.const_get($1) | |
+ begin | |
+ result = app_module::Application | |
+ rescue NameError | |
+ end | |
+ end | |
+ end | |
+ | |
+ if result.nil? && defined?(ActionController::Dispatcher) | |
+ result = ActionController::Dispatcher.new | |
+ end | |
+ | |
+ result || abort("Unable to locate the application dispatcher class") | |
+end | |
+ | |
def rails_builder(daemonize) | |
# this lambda won't run until after forking if preload_app is false | |
lambda do || | |
@@ -148,9 +167,9 @@ def rails_builder(daemonize) | |
else | |
use Rails::Rack::LogTailer unless daemonize | |
use Rails::Rack::Debugger if $DEBUG | |
+ use Rails::Rack::Static, map_path | |
map(map_path) do | |
- use Rails::Rack::Static | |
- run ActionController::Dispatcher.new | |
+ run rails_dispatcher | |
end | |
end | |
end.to_app | |
-- | |
1.6.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment