Undefined local variable or method 'rolify'

2k views Asked by At

In my Rails project, I am trying to set up user authentication and user roles using the following Gems:

  • Devise
  • Cancan
  • Rolify

I had Devise up and working perfectly, but then when I went to set up CanCan and Rolify, I get this error in the browser:

NameError in Home#index

Showing C:/Sites/JustManage/app/views/devise/menu/_registration_items.html.erb where line #1 raised:

undefined local variable or method `rolify' for #<Class:0x3f48660>
Extracted source (around line #1):

1: <% if user_signed_in? %>
2: 
3:   <li>
4:      <%= link_to('Edit registration', edit_user_registration_path) %>
Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: C:/Sites/JustManage

user.rb

class User < ActiveRecord::Base
  rolify

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :subdomain, :first_name, :last_name

  # Make sure certain attributes are unique
  validates_uniqueness_of :email, :case_sensitive => false
end

role.rb

class Role < ActiveRecord::Base
  has_and_belongs_to_many :users, :join_table => :users_roles
  belongs_to :resource, :polymorphic => true

  scopify
end

rolify.rb

Rolify.configure do |config|
  config.use_dynamic_shortcuts
end

Let me know if you need me to post contents from any of my other files!

2

There are 2 answers

6
grenierm5 On

Is it safe to assume that you installed and subsequently required the rolify gem properly?...

Please verify that rolify is listed when you run gem list and that you have added require 'rolify' at the top of your user.rb file.

0
zenben1126 On

I had the same issue. Restarting my server fixed it!

'When in doubt, ctrl-c out!'