Created
July 4, 2013 09:54
-
-
Save jmgarnier/5926412 to your computer and use it in GitHub Desktop.
Revisions
-
Jean-Michel Garnier created this gist
Jul 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ require 'cancan' # Add a setting to the application to configure the ability ActiveAdmin::Application.inheritable_setting :cancan_ability_class, "Ability" module ActiveAdmin class CanCanAdapter < AuthorizationAdapter def authorized?(action, subject = nil) cancan_ability.can?(action, subject) end def cancan_ability @cancan_ability ||= initialize_cancan_ability end def scope_collection(collection, action = ActiveAdmin::Auth::READ) collection.accessible_by(cancan_ability, action) end private # The setting allows the class to be stored as a string # to enable reloading in development. def initialize_cancan_ability ability_class_name = resource.namespace.cancan_ability_class if ability_class_name.is_a?(String) ability_class = ActiveSupport::Dependencies.constantize(ability_class_name) else ability_class = ability_class_name end ability_class.new(user) end end end