Reputation: 359
What would cause this to work in development, but not production?
I have User.find_by(["name LIKE ?", "DAN DOUGHTY"])
and it finds the user with the name "Dan Doughty"
on development server but does not find that same user in Production on Heroku. There is a User with that name on both environments.
Upvotes: 0
Views: 86
Reputation: 359
I think I am just going to use something more reliable. I chose to use Arel to fix this issue.
They’re unfortunately just a little buried and a little undocumented. And so conventional wisdom is that Rails doesn’t do case-insensitive finds. But in fact it does:
case-insensitively:
t = User.arel_table
User.find_by(t[:name].matches('DAN DOUGHTY'))
Upvotes: 1
Reputation: 23661
Note that LIKE
is case sensitive and it will match the exact string
So either downcase the name both side
User.find_by(["lower(name) LIKE ?", "DAN DOUGHTY".downcase])
Or go for ILIKE
User.find_by(["name ILIKE ?", "DAN DOUGHTY"])
Upvotes: 2