Customising the generic Rails error message

ruby-on-rails

Solution

For catching exceptions in Rails 2, `rescue_from` controller method is a great way to specify actions which handle various cases.

class ApplicationController < ActionController::Base
  rescue_from MyAppError, :with => :show_errors

  def show_errors
    render :action => "..."
  end
end

This way you can make dynamic error pages to replace the static "public/500.html" page.

Problem

Our rails app is designed as a single code base linking to multiple client databases. Based on the subdomain the app determines which db to connect to. We use liquid templates to customise the presentation for each client. We are unable to customise the generic 'We're Sorry, somethign went wrong..' message for each client. Can anyone recommend an approach that would allow us to do this. Thanks DOm

Original source