简体   繁体   English

如何在没有任何副作用的情况下使用 activeadmin 设置 cancan?

[英]How to setup cancan with activeadmin without any side effect?

I have an active admin code running which is as below我有一个活动的管理代码正在运行,如下所示

ActiveAdmin.register UserProcess, as: 'Summary' do
....
end

active_admin.rb - active_admin.rb -

config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.cancan_ability_class = "Ability"
config.on_unauthorized_access = :access_denied

I want to block user from accessing this Summary page without actually blocking his access from UserProcess.我想阻止用户访问此摘要页面,而不实际阻止他从 UserProcess 访问。

adding cannot :manage, UserProcess works for the page but then it also does not allow the user to access him other pages.添加cannot :manage, UserProcess适用于该页面,但它也不允许用户访问他的其他页面。

Also my namespace is :actadmin我的命名空间也是:actadmin

Please let me know the correct thing to write in Ability class请让我知道在能力课上写的正确内容

I solved similar thing by creating a custom page and apply cancan ability on that page.Otherwise ability was applied on resource.我通过创建一个自定义页面并在该页面上应用 cancan 能力解决了类似的问题。否则能力被应用到资源上。

ActiveAdmin.register_page "Summary" do
 menu parent: "UserProcess", label: "Summary"
  content title: "Summary" do
   .......
   .......
  end
end

and apply ability on it this way:并以这种方式对其应用能力:

class Ability
 include CanCan::Ability
  def initialize(users)
   can :manage UserProcess
   cannot :manage, ActiveAdmin::Page, name: "Summary"
  end
end

If you found by the time another cleaner solution,please edit me!如果您当时找到了另一种更清洁的解决方案,请编辑我!

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

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