Why doesn't this code produce the desired result?

前端 未结 1 769
失恋的感觉
失恋的感觉 2021-01-27 05:47
def check_beta_code
    beta_code_array = [\'AAAAAAAAAA\', \'BBBBBBBBBB\', \'CCCCCCCCCC\', \'DDDDDDDDDD\', \'EEEEEEEEEE\']

    if false == beta_code_array.include?(:bet         


        
相关标签:
1条回答
  • 2021-01-27 06:37

    Look at your conditional:

    beta_code_array.include?(:beta_code)
    

    You're checking if beta_code_array includes a symbol :beta_code. I assume you meant to pass on a string parameter? I'm not too familiar with Rails — please correct me if this isn't the right form for the User model.

    def check_beta_code beta_code
        beta_code_array = ['AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD', 'EEEEEEEEEE']
    
        unless beta_code_array.include?(beta_code)
            errors.add(:beta_code, "Invalid Beta Code")
        end
    end
    
    0 讨论(0)
提交回复
热议问题