Skip to content

Instantly share code, notes, and snippets.

@FooBarWidget
Created June 8, 2010 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FooBarWidget/429944 to your computer and use it in GitHub Desktop.
Save FooBarWidget/429944 to your computer and use it in GitHub Desktop.
From c91acde4040362f545e51d7cfcf600155354a803 Mon Sep 17 00:00:00 2001
From: Hongli Lai (Phusion) <hongli@phusion.nl>
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