Plugins - exception_handler

StarAdd to favorites

Allows you to register handlers for exceptions in your controllers like:

class ApplicationController < ActionController::Base
  class NotAuthorized < RuntimeError;end

  register_exception NotAuthorized, :not_authorized

  private

  def not_authorized
    flash[ :error ] = 'You are not authorized to perform the requested ' +
    'action.'
    render :text => '', :layout => true, :status => 401
  end
end

In this example, you could raise an ApplicationController::NotAuthorized exception anywhere in the course of processing an action, and instead of just getting an error report or a 500 error in the browser, the user would see the page with your error message and the browser gets a 401 status code.

John Wilger

http://johnwilger.com/pages/exception_handler

svn://source.johnwilger.com/plugins/exception_handler

PublicDomain

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Controllers

Tags

Comments

Add a comment
Charl 10 Aug 2007

This svn repository does not seem to be up anymore.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?