Bruno
Bruno

Reputation: 6449

What is the logic to this if statement?

I am having difficulty understanding the logic of this statement:

if (current_user.has_role? :admin, current_user.active_org)

Upvotes: 0

Views: 46

Answers (2)

Lochemage
Lochemage

Reputation: 3974

Basically testing whether admin or current_user.active_org is valid, based on whether has_role is set or not... same as:

if (current_user.has_role)
  if (admin)
    stuff...
  end
else
  if (current_user.active_org)
    same stuff...
  end
end

but just more compressed.

Upvotes: 1

jdl
jdl

Reputation: 17790

has_role? is looking at both parameters and returning a boolean. This is probably CanCan, right? If so it's saying "Is the current user an admin of the current user's active 'org'?"

Please post your Ability class if you want a more exact answer.

Upvotes: 2

Related Questions