Rails 2.3 & Using Mongrel to deploy to a subdirectory (via –prefix)
Wednesday, March 25th, 2009As many in the Rails community, our team has begin using the latest and greatest version of Ruby on Rails (2.3). We’ve been using v2.3 to develop our new Rails apps and everything is great. Great, that is, until we try to deploy to our application server.
You see, Our team runs multiple applications on the same server: apps.domain.com/app_1 apps.domain.com/app_2 etc..
We launch mongrel with something like:
mongrel_rails start --prefix /app_1
This has always worked for us, but when we tried to deploy an application with Rails 2.3 we ran into a problem. A big one. Buried down in Mongrel’s code, the following code lies:
ActionController::AbstractRequest.relative_url_root = ops[:prefix] if ops[:prefix]
This code hooks into Rails, telling it to add the subdirectory that you’re deploying to (app_1, app_2, etc) to the paths that Rails generates for you (root_url and the like). The problem is ActionController::AbstractRequest has been removed from Rails 2.3.
Seeing as the last update to Mongrel was over a year ago, we’re not very optimistic of the Mongrel team getting a fix for this out anytime soon. We also, can’t simply patch our version of mongrel, because it is also used by Rails apps around from before v2.3. Instead, we decided to temporarily hack around the problem.
I present abstract_request.rb
module ActionController
class AbstractRequest
def relative_url_root=(path)
ActionController::Base.relative_url_root = path
end
def relative_url_root
ActionController::Base.relative_url_root
end
end
end
Placing this little guy the lib/action_controller/ directory of your rails app will gracefully allow Mongrel to still make its call to AbstractRequest, hopefully refraining from breaking anything else.
So if you’re like us and are deploying multiple rails apps to subdirectories, or even if you just want to deploy a single rails app to a subdirectory, you’re likely going to run into this problem.