Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Create “Exception Filters” in Rails Using Execeptional

By Peter Cooper / December 3, 2006

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.

Comments

  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. 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..

Other Posts to Enjoy

Twitter Mentions