开发者

undefined local variable or method `role' for User:

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


role_symbols is calling role.map, but role isn't defined yet

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜