Tony
Tony

Reputation: 10208

Rails 3- Active_admin and CanCan integration

The title is very explanatory.

How can I integrate active_admin gem with cancan? I need administrative roles.

Thanks

Upvotes: 1

Views: 3723

Answers (4)

cortex
cortex

Reputation: 5206

Nowadays there is a gem that do the work: https://github.com/11factory/activeadmin-cancan

Upvotes: 0

chaitanya
chaitanya

Reputation: 1974

Following link is also helpful to set cancan with activeadmin.

https://github.com/gregbell/active_admin/wiki/How-to-work-with-cancan

Upvotes: 0

Siwei
Siwei

Reputation: 21549

for a simple case, assuming there are 2 roles: normal_user , admin,

if you just want to "admin" to access "/admin" (activeadmin's default namespace), while "normal_user" can not, I suggest you take a look a hook method:

# config/initializers/active_admin.rb
config.before_filter :check_user_role

# define this method in applicaton_controller.rb
def check_user_role
  redirect_to root_path unless current_user.role == "admin"
end

Upvotes: 1

Robbie Done
Robbie Done

Reputation: 1157

You may want to follow this guide

Robbie

Upvotes: 4

Related Questions