adding custom message argument to unauthorized! method - closes #18

This commit is contained in:
Ryan Bates
2009-12-15 10:53:05 -08:00
parent 67416532f4
commit ef22de689b
4 changed files with 20 additions and 13 deletions

View File

@@ -123,24 +123,22 @@ module CanCan
# unauthorized! if cannot? :read, @article
# end
#
# You can rescue from the exception in the controller to specify
# the user experience.
# The unauthorized! method accepts an optional argument which sets the
# message of the exception.
#
# You can rescue from the exception in the controller to define the behavior.
#
# class ApplicationController < ActionController::Base
# rescue_from CanCan::AccessDenied, :with => :access_denied
#
# protected
#
# def access_denied
# flash[:error] = "Sorry, you are not allowed to access that page."
# rescue_from CanCan::AccessDenied do |exception|
# flash[:error] = exception.message
# redirect_to root_url
# end
# end
#
# See the load_and_authorize_resource method to automatically add
# the "unauthorized!" behavior to a RESTful controller's actions.
def unauthorized!
raise AccessDenied, "You are unable to access this page."
def unauthorized!(message = "You are not authorized to access this page.")
raise AccessDenied, message
end
# Creates and returns the current user's ability. You generally do not invoke