All threads / Active Admin Authorization by CanCan gem when User and ActiveAdmin have same model

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Active Admin Authorization by CanCan gem when User and ActiveAdmin have same model

Shaheryar Imtiaz asked in Rails

I already had a User model with different roles handled by cancan gem. Now i have implemented active admin gem in the same User model with another role. Now i could not figure out how to restrict active admin views. I have tried different things like
can :read, ActiveAdmin::Page, name: "Dashboard", namespace_name: "admin"
in abilty.rb for the active admin role but this stuck in an infinite loop of requests to "/admin" and displays nothing. Thanks for help in advance.
Here are my active admin configurations

ActiveAdmin.setup do |config|
  config.root_to = 'users#index'
    config.site_title = "Application"

  config.authentication_method = :authenticate_user!

  config.authorization_adapter = ActiveAdmin::CanCanAdapter

  config.cancan_ability_class = "Ability"

  config.current_user_method = :current_user

  config.logout_link_path = :destroy_user_session_path
  config.logout_link_method = :delete

end
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.