0
votes

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
1

1 Answers

1
votes

Did you forget to redirect to the dashboard like this?

config.on_unauthorized_access = :access_denied
class ApplicationController < ActionController::Base
  def access_denied(exception)
    redirect_to admin_dashboard_path, alert: exception.message
  end
end