Possible Duplicate:
Why doesn't this code produce the desired result?
I have the code:
def check_beta_code
beta_code_array = ['AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD', 'EEEEEEEEEE']
beta_code_array.each do |code|
if :beta_code != code
errors.add(:beta_code, "Invalid Beta Code")
end
end
end
The problem with this code is that even if someone inputs a correct password, 4 errors are still generated because the other 4 aren’t correct.
I’m assuming this code is in a model somewhere. You can try creating a model that holds the beta codes and store some values in the DB. Then it’s just a matter of querying the db for the code and seeing if there’s a match:
If you want to use your snippet, you can always use the
member?method for an array.