[英]CanCan is not allowing custom action/pages in Spree backend
I have create a new role in Spree and limited it with CanCan to only one controller. 我在Spree中创建了一个新角色,并使用CanCan将其限制为仅一个控制器。 However it does not allow access to custom actions/pages. 但是,它不允许访问自定义操作/页面。
create, delete, index etc
The above actions are accessible, yet my 'clean' view is not. 可以执行上述操作,但是我的“干净”视图无法访问。
Controller - 控制器-
def clean
@handbags = Spree::Handbag.is_clean.page(params[:page]).per(50)
end
AbilityDecorator - 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)
Also tried - 还尝试了-
can [:clean, :admin, :index etc..], Spree::Handbag
Thanks for any help. 谢谢你的帮助。
I got around this by overriding collection_actions and adding the actions I needed to work - 我通过重写collection_actions并添加了我需要工作的动作来解决这个问题-
def collection_actions
[:index, :clean, :repair, :colour]
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.