CanCan错误'未定义的方法角色?' 与设计

dan*_*iel 7 authorization devise cancan ruby-on-rails-3

嘿,我希望你能帮助我:

我正在阅读本教程

http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/我一步一步地做了.

我不太确定在哪里放置角色? - 教程中的方法,因为它没有说放置它的位置.

现在,当我想要sign_up或Sign_in时,它会给我这个错误

非常感谢

Sin*_*ris 14

您需要在用户模型中添加它(app/models/user.rb)

class User < ActiveRecord::Base
  has_and_belongs_to_many :roles
  devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable

  def role?(role)
      return !!self.roles.find_by_name(role.to_s.camelize)
  end
end
Run Code Online (Sandbox Code Playgroud)