0

在我的 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

用户.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

角色.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

如果您需要我从我的任何其他文件中发布内容,请告诉我!

4

2 回答 2

5

我遇到过同样的问题。重新启动我的服务器修复了它!

“如有疑问,请按 ctrl-c 退出!”

于 2014-01-19T00:11:39.007 回答
1

假设您正确安装并随后需要 rolify gem 是否安全?...

请确认 rolify 在您运行时已列出,gem list并且您已require 'rolify'在 user.rb 文件的顶部添加。

于 2013-12-04T16:36:30.500 回答