Brady
Brady

Reputation: 131

Have CanCan use Active Admin user?

I'm using Devise and CanCan for authorization on the frontend of a Rails 3 app. I also have Active Admin as the interface for the backend. I'm trying to create different roles for admins in the backend. Both ends have a login form that uses different 'user' models & tables. The problem is that CanCan fetches the current user from the frontend (grabbing the current user object) and uses that to see if someone in the backend has the correct permissions.

So, how I can have CanCan correctly grab the admin user that's logged in?

If anyone needs more information, I'll be glad to supply it.

Upvotes: 7

Views: 6504

Answers (1)

Jatin Ganhotra
Jatin Ganhotra

Reputation: 7035

I have not used ActiveAdmin before, but have used Devise and Cancan in a couple of projects before.

Having looked at Active Admin Documentation,

Set the method that controllers should call to authenticate the current user with:

  # config/initializers/active_admin.rb
  config.authentication_method = :authenticate_admin_user!

Set the method to call within the view to access the current admin user

  # config/initializers/active_admin.rb
  config.current_user_method = :current_admin_user

You can override Cancan behaviour in your application, by looking at :current_admin_user instead of :current_user.

Refer here Cancan changing defaults.
If you still can't get it, post your problems, where you are stuck.

Upvotes: 10

Related Questions