Tuesday, December 4, 2007

Generate Error Pages In Capistrano With ERb

Say you've got several error pages which all essentially render a partial - but because they're error pages, you don't want them to be dependent on Rails working correctly. A nice solution is to create the "partial" in ERb and have Capistrano build the static HTML when you do your cap:deploy.

This is especially useful during planned downtime, since it becomes very very easy to make precise and specific error pages, rather than resorting to the generic "We're down for unspecified reasons, and this will persist for an unspecified amount of time" approach.

Using ActionPack would seem the way to go, especially if you've used ActiveRecord outside of Rails and seen how easy it is, but ActionPack is more tightly coupled, unfortunately. You have to require both ActionController and ActionView manually, and in that order, and then require a series of internal libraries. All you're probably doing is a few variable substitutions anyway, so ERb is much more practical.