【问题标题】:CanCan is not allowing custom action/pages in Spree backendCanCan 不允许 Spree 后端中的自定义操作/页面
【发布时间】:2015-10-22 16:41:44
【问题描述】:

我在 Spree 中创建了一个新角色,并使用 CanCan 将其限制为只有一个控制器。但是它不允许访问自定义操作/页面。

create, delete, index etc

上述操作可以访问,但我的“干净”视图不是。

控制器 -

  def clean
    @handbags = Spree::Handbag.is_clean.page(params[:page]).per(50)
 end

AbilityDecorator -

  class AbilityDecorator
  include CanCan::Ability
  def initialize(user)
    if user.respond_to?(:has_spree_role?) && user.has_spree_role?('technical')
        can :manage, Spree::Handbag
    end
  end
end

Spree::Ability.register_ability(AbilityDecorator)

也试过了-

    can [:clean, :admin, :index etc..], Spree::Handbag

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails devise cancan spree


    【解决方案1】:

    我通过覆盖 collection_actions 并添加我需要的操作来解决这个问题 -

      def collection_actions
    [:index, :clean, :repair, :colour]
      end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-14
      • 2017-01-13
      • 2018-06-25
      • 2018-10-04
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多