我让ActiveAdmin和CanCan一起工作。我已经设置了管理员和客户权限。
现在我想根据CanCan设置的权限隐藏“新建”、“编辑”和“删除”按钮,但下面一行显示错误...
config.clear_action_items! :if => proc{can? (:destroy, Shipment)}这个也是
:if => proc{ can?(:destroy, Shipment)}, actions :all, :except => [:new, :create, :update, :edit, :destroy]发布于 2012-11-07 06:36:52
我使用这个猴子补丁在显示按钮之前检查权限。
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
endhttps://stackoverflow.com/questions/8934892
复制相似问题