Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Rolify how to test for multiple roles

I would like to test for multiple roles using rolify.

I tried this and it didn't work:

<% if current_user.has_role? [:technician, :admin] %>

Thanks for the help!

UPDATE1

I'm trying to test for :technician or :admin - this works but seems like there should be a shorter way:

if current_user.has_role? :technician or current_user.has_role? :admin
like image 781
Reddirt Avatar asked Dec 04 '25 16:12

Reddirt


1 Answers

I'd recommend you test something like current_user.has_any_role? :technician, :admin, it should return you the boolean you're expecting :)

like image 106
Miguelgraz Avatar answered Dec 06 '25 07:12

Miguelgraz