Daniel
Daniel

Reputation: 359

Rails - Add custom route constraint for "/admin"

I am using ActiveAdmin on my current Rails application. In my routes, I would like to create a route constraint so that "/admin" namespace would be accessible just to users that have an attribute admin on true (boolean attribute).

I tried looking into Rails route constraints but I haven't figured out yet how to properly use a defined method to validate/invalidate the constraint.Something like

def check_me
  current_user.admin #current_user method from Devise
end

to be used

How can this be accomplished?

Upvotes: 1

Views: 453

Answers (1)

Mahmoud Sayed
Mahmoud Sayed

Reputation: 668

You can customize your ActiveAdmin authentication, check it here.

define your method:

def check_me
  current_user.admin?
end

then change your configuration:

config.current_user_method = :check_me

Upvotes: 1

Related Questions