gpt4 book ai didi

ruby-on-rails-3 - CanCan 错误 'undefined method role?' 与设计

转载 作者:行者123 更新时间:2023-12-04 10:11:57 30 4
gpt4 key购买 nike

嘿我希望你能帮助我:

我正在学习本教程

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

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

现在当我想注册或登录时它给了我这个错误

非常感谢

最佳答案

您需要将其添加到用户模型中 ( 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

关于ruby-on-rails-3 - CanCan 错误 'undefined method role?' 与设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4675304/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com