繁体   English   中英

CanCan在Spree后端不允许自定义操作/页面

[英]CanCan is not allowing custom action/pages in Spree backend

我在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

谢谢你的帮助。

我通过重写collection_actions并添加了我需要工作的动作来解决这个问题-

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM