I am doing ajax validation when a user signs up for my application to see if the username already exists. The request is made whenever you unfocus/blur the username field. Locally I am using MySQL and on Heroku it's Postgres, so I'm assuming the issue lies there somehow because this functions perfectly locally on my dev machine.
The username registered is Matt for example...
Development:
- Matt = taken is true
- matt = taken is true
- MATT = taken is true
- MaTt = taken is true, etc...
Production:
- Matt = taken is true
- matt = taken is false
- MATT = taken is false
- MaTt = taken is false
And here is the method (you can even see I went a step further to try and force it to downcase, again works locally how it should, but not on production)...
def checkname
scrubb = ActionController::Base.helpers.sanitize(params[:username], :tags => '')
user = User.find_by_username(scrubb, :conditions => [ "lower(username) = ?", scrubb.downcase ])
if user.blank?
render :json => { :isAvailable => true }
else
render :json => { :isAvailable => false }
end
return
end
**EDIT**
This is the output of the generated MySQL query:
SELECT `users`.* FROM `users` WHERE `users`.`username` = 'MATT' AND (lower(username) = 'matt') LIMIT 1
So, it looks like the real issue is that AND statement Rails is generating. How would I remove that?