Skip navigation

Monthly Archives: March 2011

I recently had the following error while configuring Nginx with Unicorn on Rails 2.3.8

in my config.ru, I had the following:

(taken from the Ruby on Rack instructions on the ‘official’ guide page, http://guides.rubyonrails.org/rails_on_rack.html )
config.ru
======
require “config/environment”

use Rails::Rack::LogTailer
use ActionDispatch::Static
run ActionController::Dispatcher.new

This was giving the following annoying error when trying to start the unicorn server:

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant’: uninitialized constant ActionDispatch (NameError)
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing’
from config.ru:5
from /usr/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/builder.rb:46:in `instance_eval’
from /usr/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/builder.rb:46:in `initialize’
from config.ru:1:in `new’
from config.ru:1

It turns out that a patch submitted to unicorn_rails gave the hint (http://bogomips.org/unicorn.git/diff/bin/unicorn_rails?h=body-keepalive&id2=98ea5cca50b907e20d6357f425d7789bac1d1a47 )

The fix was to replace the line #use ActionDispatch::Static with:
use Rails::Rack::Static

The new config.ru thus became:
use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new

I am guessing this had to be done because ActionDispatch::Static isn’t present in this version of Rails.