Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/christhekeele/contingency-rails

A Contingency Plan integration for Rails.
https://github.com/christhekeele/contingency-rails

Last synced: about 2 months ago
JSON representation

A Contingency Plan integration for Rails.

Awesome Lists containing this project

README

        


# Contingency-Rails

> "Freedom is the recognition of contingency."

> * *Richard M. Rorty*

Contingency-Rails provides [Contingency](https://github.com/christhekeele/contingency) integration for [Rails](http://rubyonrails.org/).


## Table of Contents

* [Installation](#installation)
* [Configuration](#configuration)
* [Extra Routes](#extra-routes)
* [Error Codes](#error-codes)
* [Catch-all Routes](#catch-alls)
* [Contributing to Contingency-Rails](#contributing-to-contingency-rails)


## Installation

Add this line to your application's Gemfile:

gem 'contingency-rails', '~> 3.0'

Then, execute:

$ bundle

Finally, add this to your `ApplicationController`:

include Contingency::Plan


## Configuration

Contingency-Rails uses the same configuration object as Contingency, but has different defaults. Run 'rake contingency:generate:rails:config' to get the example initializer. If you decide to skip this step, make sure you call `Contingency.configure` *somewhere* in your boot process, and that you have a view called `error` at `app/views/errors/`.


## Extra Routes

Once you've configured your errors, you can get some additional features out of Contingency by adding a few routes to your `routes.rb`


### Error Codes

At the bottom of your routes, add this line:

match "/:code", to: 'application#error', as: :error, constraints: {code: /\d{3}/}

This controller action allows you to access your custom error pages directly. This means in development mode you won't have to change `config.consider_all_requests_local` to true and intentionally raise an error in one of your controllers just to see if your two lines of CSS improved the feel of your error page.


### Catch-all Routes

At the **VERY** bottom of your routes, add this line:

match '/*invalid_url', to: 'application#routing_error'

This Rails-specific controller action enables Contingency to catch `ActionController::RoutingError` exceptions. Normally, invalid URLs in Rails are handled by Rack, so the Contingency Plan living in your controller can't rescue from it. Append this globbed route to the very end of your routes, and it can.


## Contributing to Contingency

1. Fork it
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Push to the branch (`git push origin my-new-feature`)
1. Create new Pull Request