def check_beta_code
beta_code_array = ['AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD', 'EEEEEEEEEE']
if false == beta_code_array.include?(:beta_code)
errors.add(:beta_code, "Invalid Beta Code")
end
end
I created a user, user = User.new{:beta_code=>'AAAAAAAAAA'} and then user.save #=> false and then i do user.errors #=>{:beta_code=>["Invalid Beta Code"]}
Why is it giving the error even though :beta_code is equal to one of the values?
Help!
Look at your conditional:
You’re checking if
beta_code_arrayincludes 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.