lib/trust/controller.rb
# Enables authorization in controller
#
# +trustee+ accepts +:off+ or a hash of +callback+ options such as +:except+ and +:only+
#
# +trustee+ automatically calls the class methods: +set_user+, +load_resource+ and +access_control+
# +trustee+ accepts +:off+ for +set_user+, +load_resource+ and +access_control+ individually
#
# +trustee+ will raise an Trust::AccessDenied exception if the user is not permitted the action
#
# ==== Examples
#
#   # enable permission check for all restful actions
#   class AccountsController < ApplicationController
#     login_required
#     trustee
#   end
#
#   # disable all permission check
#   class PasswordController < ApplicationController
#     # assuming login_required and trustee has been in your application controller
#     trustee :off
#   end
#
#   # enable permission check and loading for only :new and :create action
#   class AccountsController < ApplicationController
#     login_required
#     trustee :only => [:new, :create]
#   end
#
#   # enable permission check for all restful actions, but without loading resources
#   class AccountsController < ApplicationController
#     login_required
#     trustee :load_resource => :off
#     model :objects
#   end
#
# ==== Caching Trust::AccessDenied exception
# Normally an exception handler is included in the ApplicationController. Example:
#   class ApplicationController < ActionController::Base
#     rescue_from Trust::AccessDenied do |exception|
#       redirect_to root_url, :alert => exception.message
#     end
#   end
Enables authorization in controller



+trustee+ will raise an Trust::AccessDenied exception if the user is not permitted the action

Examples

enable permission check for all restful actions
class AccountsController < ApplicationController
login_required
trustee
end

disable all permission check
class PasswordController < ApplicationController
assuming login_required and trustee has been in your application controller
trustee :off
end



enable permission check for all restful actions, but without loading resources
class AccountsController < ApplicationController
login_required
trustee :load_resource => :off
model :objects
end

Caching Trust::AccessDenied exception
Normally an exception handler is included in the ApplicationController.
Enables authorization in controller + trustee + will raise an Trust :: AccessDenied exception if the user is not permitted the action Examples enable permission check for all restful actions class AccountsController < ApplicationController login_required trustee end disable all permission check class PasswordController < ApplicationController assuming login_required and trustee has been in your application controller trustee : off end enable permission check for all restful actions but without loading resources class AccountsController < ApplicationController login_required trustee : load_resource = > : off model : objects end Caching Trust :: AccessDenied exception Normally an exception handler is included in the ApplicationController .
def trustee(*args)
        module_eval do
          include TrustInstanceMethods
          set_user *args
          load_resource *args
          access_control *args
          helper_method :can?, :resource, :resource?
        end
      end
def trustee ( * args ) module_eval do include TrustInstanceMethods set_user * args load_resource * args access_control * args helper_method :can? , :resource , :resource? end end
Enables authorization in controller
+trustee+ accepts +:off+ or a hash of +callback+ options such as +:except+ and +:only+
Enables authorization in controller + trustee + accepts + : off + or a hash of + callback + options such as + : except + and + : only +
args