Using Mongrel with Rails 2.2+ and prefix

First, don’t. Mongrel seems to be a dead product, I think everyone’s moved over to mod_rails/passenger. Because mod_rails/passenger (what’s that product actually called these days?) is nice. Just use that, mongrel hasn’t been updated in years now and doesn’t look like it will be.

But in case you have to. And you run into that thing where you want to use mongrel’s “–prefix” argument, but it doesn’t work with Rails 2.2+, because mongrel tries to call API that doens’t exist in Rails anymore. What do you do?

Some people patch mongrel. Some people give up on using “–prefix” in mongrel, and just set the prefix in their Rails environment.rb (a much less flexible arrangement).  But I actually found a better solution, which worked out fine for me back when I was using it, before I gave up on mongrel and switched the application involved on Rails 2.2+ over to passenger.

Someone just emailed me to ask for it, and it took me a while to track down, it didn’t google well, so I’ll stick it here so it maybe googles better, and I can find it again if I need it.

###################
# Fix for mongrel which still doesn't know about Rails 2.2's changes, grr.
# We provide a backwards compatible wrapper around the new
# ActionController::base.relative_url_root,
# so it can still be called off of the actually non-existing
# AbstractRequest class.

module ActionController
  class AbstractRequest < ActionController::Request
    def self.relative_url_root=(path)
      ActionController::Base.relative_url_root=(path)
    end
    def self.relative_url_root
      ActionController::Base.relative_url_root
    end
  end
end
###################

Pretty nifty, huh? I think I came up with that myself, but can’t remember, maybe I got it from somewhere else, but I’m surprised that it wasn’t already google-able, it’s such a nifty solution which seemed to work fine as far as I can remember. Maybe cause everybody has already moved over to passenger, and nobody cares anymore.

Leave a comment