未定义的局部变量或方法“角色”对于用户:
当我尝试访问我的任何视图时,我不断收到该错误。我正在尝试设置声明性授权。
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :username
end
ROLES = %w[admin moderator subscriber]
has_and_belongs_to_many :channels
has_many :channel_mods
named_scope :with_role, lambda { |role| {:conditions => "roles_mask & #{2**ROLES.index(role.to_s)} > 0 "} }
def role_symbols
role.map do |role|
role.name.underscore.to_sym
end
end
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
end
def roles
ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
end
end
I keep getting that error when trying to access any of my views. I'm trying to setup Declaritive Authorization.
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :username
end
ROLES = %w[admin moderator subscriber]
has_and_belongs_to_many :channels
has_many :channel_mods
named_scope :with_role, lambda { |role| {:conditions => "roles_mask & #{2**ROLES.index(role.to_s)} > 0 "} }
def role_symbols
role.map do |role|
role.name.underscore.to_sym
end
end
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
end
def roles
ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
role_symbols 正在调用 role.map,但角色尚未定义
role_symbols is calling role.map, but role isn't defined yet