Question

I check the docs but it only works when include 1 more global role. how can I do multiple role checking without global role?

user.add_role :admin
user.add_role(:user, group)
user.add_role(:mentor, group)
user.has_all_roles? :admin, {:name => :mentor, :resource => group} 
=> true
user.has_all_roles? {:name => :mentor, :resource => group}, {:name => :user, :resource => group}
=> SyntaxError: (irb):27: syntax error, unexpected =>, expecting '}'
user.has_any_role? :admin, {:name => :mentor, :resource => group}, {:name => :user, :resource => group}
=> true
user.has_any_role? {:name => :mentor, :resource => group}, {:name => :user, :resource => group}
=> SyntaxError: (irb):30: syntax error, unexpected =>, expecting '}'
Was it helpful?

Solution

Very annoying, but simply solved! Reason is that by writing

user.has_all_roles? {...}

you tell ruby: I'm giving a block to this method call... And that's obviously not what you want.

Simple fix: just add parentheses to your method call:

user.has_all_roles?( {...} )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top