2012-01-19 28 views
4

我有ActiveAdmin和CanCan一起工​​作。我已經設置了管理員和客戶權限。Rails 3 ActiveAdmin。根據CanCan權限隱藏按鈕

現在我想隱藏的新建,編輯和刪除根據慘慘設置的權限,但以下行給我的錯誤按鈕...

config.clear_action_items! :if => proc{can? (:destroy, Shipment)} 

這個也是

:if => proc{ can?(:destroy, Shipment)}, actions :all, :except => [:new, :create, :update, :edit, :destroy] 
+0

我相信'current_user'必須是availab爲了檢查這種能力。我懷疑它在任何配置文件中都可用。 – jibiel

回答

0

我使用這個猴子補丁來檢查顯示按鈕之前的權限

module ActiveAdmin 
    class Resource 
    module ActionItems 

     # Adds the default action items to each resource 
     def add_default_action_items 
     # New Link on all actions except :new and :show 
     add_action_item :except => [:new] do 
      if controller.action_methods.include?('new') and can? :create, active_admin_config.resource_class 
      link_to(I18n.t('active_admin.new_model', :model => ''), new_resource_path, 
      :class => "new-link" 
      ) 
      end 
     end 

     # Edit link on show 
     add_action_item :only => :show do 
      if controller.action_methods.include?('edit') and can? :update, active_admin_config.resource_class 

      link_to(I18n.t('active_admin.edit_model', :model => ''), edit_resource_path(resource), 
      :class => "edit-link" 
      ) 


      end 
     end 

     # Destroy link on show 
     add_action_item :only => :show do 
      if controller.action_methods.include?("destroy") and can? :destroy, active_admin_config.resource_class 

      link_to(I18n.t('active_admin.delete_model', :model => ''), 
       resource_path(resource), 
       :class => "delete-link" , 
       :method => :delete, :data => {:confirm => I18n.t('active_admin.delete_confirmation')}) 

      end 
     end 
     end 
    end 
    end 
end