2010-11-28 5 views
0

내보기에 액세스하려고 할 때 계속 오류가 발생합니다. Declaritive Authorization을 설정하려고합니다.사용자에 대한 정의되지 않은 로컬 변수 또는 메소드`role ':

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 

답변

1

role_symbols는 role.map를 호출하지만 역할은 아직

+0

감사를 정의하지, 난 당신이 생각 루비와 순서가 일을 정의 할 수 있다고 생각? –

+0

역할은 어디서나 정의 된 것처럼 보이지 않습니다. 대신 역할 (복수형)을 사용 하시겠습니까? –

+0

def roles는 정의입니다. 나는 각 사용자가 하나 이상의 롤을 가질 수 있기 때문에 yes @ plural을 추측 할 것입니다. –

관련 문제