在我的Rails项目中,我正在尝试使用以下Gems设置用户身份验证和用户角色:
我设计得很好并且工作得很好但是当我去设置CanCan和Rolify时,我在浏览器中出现了这个错误:
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
如果您需要我发布我的任何其他文件中的内容,请告诉我们!
答案 0 :(得分:4)
我有同样的问题。重新启动我的服务器修复了它!
'如果有疑问,请按ctrl-c!'
答案 1 :(得分:1)
假设您已正确安装并随后需要rolify gem可以安全吗?...
运行gem list
并确认已在user.rb文件顶部添加require 'rolify'
时,请确认列出了rolify。