How to correctly handle errors for "PG :: ConnectionBad could not connect to the server"?

My application is just typical Rails with Postgresql (in fact, Postgres application for OS X). I would like to add exception handling when the Rails application cannot connect to the database and shows the plain text of the connection error, instead of the Rails error page (or later it could be a static HTML error page).

I tried to add an exception below to application_controller.rb.

# from app/controllers/application_controllers.rb
-------------------------------------------------
  rescue_from PG::ConnectionBad, with: :database_connection_error

  def :database_connection_error
    render plain: "Could not connect to the Database"
  end

  (code ommited)

but it does not make plain text. (I also use this exception fragment on other controllers. It works, but it handles another exception, for example, I use it to handle the error ActiveRecord::RecordNotFound)

PG::ConnectionBad , ?

.

+4

All Articles