has_role fail on uninitialized constant User::RolesUser

102 views
Skip to first unread message

jarcec

unread,
Jan 20, 2009, 5:03:50 AM1/20/09
to Rails Authorization Plugin
Hello,
I've tried to use this plugin in rails 2.2 and unfortunately it always
fail on uninitialized constant User::RolesUser. I've created migration
as usual (e.g I copy&paste migration file from 2.1.2 application), so
by mine opinion the database is O.K. and the problem is hidden
somewhere else.

Log from console:
>> user.has_role('user')
NameError: uninitialized constant User::RolesUser
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
active_support/dependencies.rb:102:in `const_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/base.rb:2049:in `compute_type'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/base.rb:2045:in `compute_type'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:151:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:151:in `klass'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:244:in `source_reflection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:244:in `collect'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:244:in `source_reflection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/reflection.rb:275:in `check_validity!'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/associations/has_many_through_association.rb:5:in
`initialize'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/associations.rb:1297:in `new'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/associations.rb:1297:in `roles'
from /home/jarcec/Projects/nisfsu/vendor/plugins/rails-
authorization-plugin/lib/publishare/object_roles_table.rb:43:in
`has_role'
from (irb):4

What's interesting to me is the name of constant 'RolesUser' -
shouldn't it be RolesUsers? (in HABTM relationship)

Do you have idea what i'm doing wrong?

Best regards
Jarek 'Jarcec' Cecho

timg

unread,
Jan 20, 2009, 1:51:39 PM1/20/09
to Rails Authorization Plugin
> What's interesting to me is the name of constant 'RolesUser' -
> shouldn't it be RolesUsers? (in HABTM relationship)

I had exactly the same problem in rails 2.2.2.
I renamed role_user.rb to roles_user.rb and the class from RoleUser to
RolesUser and it all appears to work now.

kind of odd that the initial setup doesn't work. This hasn't changed
in Rails 2.2.x has it?

timg

Tom Cocca

unread,
Jan 22, 2009, 10:11:06 AM1/22/09
to Rails Authorization Plugin
Timg - thanks for the tip - Changing the file name and the class name
makes the plugin work again. Why did the plugin change?

This fix should probably go into the master on Github.
Thanks again,

Oh by the way I am running rails 2.2.2

~ Tom

Glenn Rempe

unread,
Jan 22, 2009, 5:20:47 PM1/22/09
to Rails Authorization Plugin
I have applied some patches for this from Lennart Melzer (Thank you!).

I have also updated the test suite with the new code and all existing
tests are passing clean.

http://github.com/DocSavage/rails-authorization-plugin/commits/

Hopefully this resolves the issues that came about as the result of
previous breaking commits.

Glenn
Reply all
Reply to author
Forward
0 new messages