Create “Exception Filters” in Rails Using Execeptional

In Cool, Enterprise, Ruby on Rails

Scott Fleckenstein has developed a plugin for Ruby on Rails called Exceptional that 'brings exception handling into the world of Rails filters'. The code speaks for itself on this one:

class SampleController <  ApplicationController
  handles AccessDeniedError,
    :with => :access_denied,
    :only => [:supah_sekret_akshun]

  def supah_sekret_akshun
    ...
    raise AccessDeniedError
    ...
  end

  private
  def access_denied
    render :text => 'no, u kant'
  end
end

There's a bit more to it than that, so check out the official plugin site for examples and how to download the plugin.

Vaguely Related Posts (Usually)

2 Comment Responses to “Create “Exception Filters” in Rails Using Execeptional”

  1. #1
    Danno Says:

    This sort of reminds me of Lisp's before, after, and around AOP stuff for the CLOS.

    I know there were some people yakking about AOP libraries on the Ruby List a long while ago... know of any developments in that area?

  2. #2
    Peter Cooper Says:

    Are you referring to AspectR? Unfortunately that page seems kinda old now, although I'm sure I heard something more recent about it..