Exceptional
Exceptional is a plugin for Ruby on Rails that brings exception handling into the world of RoR filters. Through two declarative statements that are similar in style to filter declarations in your controllers you get easy and powerful exception handling in your application.
- handles:
- The handles method allows you to specify a method that will handle an exception that is raised within your application and not caught by a normal rescue claus
- raises:
- The raises directive provides a exception-based version of the verify directive built into ruby on rails. This directive achieves its work using standard before_filters under the covers, and as such it follows the normal filter semantics.
Install
script/plugin install http://code.nullstyle.com/git/exceptional
See the README for the full docs. See below to see some sample incovations of the Exceptional plugin to get an idea of what you can do with it.
An invocation of the handles directive
class SampleController < ApplicationController
handles AccessDeniedError,
:with => :accessdenied,
:only => [:supahsekret_akshun]
def supah_sekret_akshun
...
raise AccessDeniedError
...
end
private
def access_denied
render :text => 'no, u kant'
end
end
Sample invocations of the raises directive
class SampleController < ApplicationController
raises InvalidUpdateError, :unless => {:params => :id}, :only => :update
raises BadJuju, :if => {:flash => :notice}, :only => :new
raises AccessDeniedError :except => [:show, :list] do
!@account.authorize :write, :update, :destroy
end
end











