martinrehfeld / role_model

RoleModel is the framework agnostic, efficient and declarative way to do user roles.
http://rdoc.info/github/martinrehfeld/role_model/master/frames
MIT License
324 stars 45 forks source link

Error when querying a role #4

Closed abhas closed 13 years ago

abhas commented 13 years ago

Hi Martin,

When I'm trying to query the role of a user object, I get an undefined method error. For example:

>> u.roles = [:admin, :depthead]
=> [:admin, :depthead]
>> u.save
=> true
>> u
=> #<User @id=1 @name="depthead1" @password="pass" @roles_mask="3" 
>> u.roles
NoMethodError: undefined method `&' for "3":String
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `roles'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `reject'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `roles'
from (irb):11
>> u.has_role? :admin
NoMethodError: undefined method `&' for "3":String
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `roles'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `reject'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:11:in `roles'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:42:in `has_role?'
from (irb):12:in `any?'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:42:in `each'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:42:in `any?'
from /var/lib/gems/1.8/gems/role_model-0.6.0/lib/role_model/implementation.rb:42:in `has_role?'
from (irb):12

No matter what I do, I keep getting the same error. Can you help me out?

Thanks, Abhas.

martinrehfeld commented 13 years ago

Sure thing! roles_mask is supposed to be an Integer. You should change your model/schema accordigly.

Cheers, Martin

abhas commented 13 years ago
You're right! That is exactly what I was missing. Thanks a lot... :) -abhas.