I want to check to see if the email address that a new person uses when registering is a duplicate of an existing record.
Here is the code:
post '/signup' do
email_address = params['email_address']
username = params['username']
password = params['password']
@duplicate = DB[:users].select(:email_address).where('email_address = ?', email_address)
if email_address = @duplicate
redirect "/?msg=Email address already in use. Try again"
return
end
end
This blocks all attempts even when the email address is not a duplicate and redirects with the error message.
If I substitute @duplicate
with duplicate
(without the @ mark) then same result, all attempts blocked. If I use ==
instead of =
then duplicate email addresses are ignored and no attempts are blocked.
I know the query:
DB[:users].select(:email_address).where('email_address = ?', email_address)
is correct because I have tested it. So I assume the problem lies with the construction of the if clause.