I am making a Rails app that uses the Rolify gem with Devise and CanCan.
Running the rolify generators like this
rails g rolify:role
put the rolify method at the top of the Users model like so
class User < ActiveRecord::Base
rolify
In addition to creating the Role.rb model.
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
scopify
end
I haven't done anything else with rolify yet. When I try to load the Users in rails console, however, I get the following error.
>> User.all
NameError: undefined local variable or method `rolify' for #<Class:0x007f813d32ce48>
I'm using Rails 3.2.12
Ruby Version
ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
I assume this is not expected behavior. Can anyone suggest a solution. It would not be worth it for me to use rolify if I can't access the User model in the console.
Tomoko, try adding extend Rolify
before rolify, like this:
class User < ActiveRecord::Base
extend Rolify
rolify
end