ruby on rails - How to check if the user should be assigned the role admin -


the goal of method check when user signs up, if on list of users should admins.

i new ruby , think syntax error:

  def set_role     if self[:email] == ("email@gmail.com" || "sample@gmail.com" || "test@gmail.com")         self[:role] = "admin"      else       self[:role] = "customer"     end   end 

this time use case statement:

def set_role   self[:role] = case self[:email]                 when "email@gmail.com", "sample@gmail.com", "test@gmail.com"                   'admin'                 else                   'customer'                 end end 

it's easy add new values when test.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -