2014-12-01 2 views
0

이 방법의 목표는 관리자가되어야하는 사용자 목록에있는 경우 사용자가 가입 할 때를 확인하는 것입니다.사용자에게 역할이 할당되어야하는지 확인하는 방법 관리자

내가 루비에 새로운 오전 그냥 구문 오류라고 생각 :

def set_role 
    if ["[email protected]", "[email protected]", "[email protected]"].include?(self[:email]) 
    self[:role] = "admin" 
    else 
    self[:role] = "customer" 
    end 
end 

이 코드 : 당신은 이메일의 배열이 같은 현재의 전자 우편을 포함하고 있는지 확인 할

def set_role 
    if self[:email] == ("[email protected]" || "[email protected]" || "[email protected]") 
     self[:role] = "admin" 
    else 
     self[:role] = "customer" 
    end 
    end 

답변

1

이것은 case 문을 사용할 수있는 좋은 시간이 될 것입니다 :

def set_role 
    self[:role] = case self[:email] 
       when "[email protected]", "[email protected]", "[email protected]" 
        'admin' 
       else 
        'customer' 
       end 
end 

when 테스트에 새 값을 쉽게 추가 할 수 있습니다.

관련 문제