For an actual solution I recommend one of the other answers, but here's how it could work the way you originally intended (aka. what went wrong).
The problem is the condition at the end of the line: unless current_client.role == 'admin' || 'dev'
What ruby does here is not what you think; 'admin' || 'dev'
is evaluated as 'admin'
, so the entire condition is equivalent to unless current_client.role == 'admin'
.
The way the ||
operator works is:
- If the first operand is truthy, it is the result of the operation.
- If the first operand is falsey, the second operand is the result of the operation.
For example, true || false
evaluates to true, 'hello' || 'world'
is 'hello'
and nil || 'world'
evaluates to 'world'.
The correct condition would be unless current_client.role == 'admin' or current_client.role == 'dev'
or
does the same as ||
, but with higher precedence.