This should do it:
def find
User.where("lower(name) = ?", params[:search].downcase)
end
By making the db entry lowercase and the search params lowercase, then case insensitivity is no longer an issue.
Also, the return
statement is not needed in Ruby since we have implicit return statements.
How does it work?
You can pass raw SQL in to the .where
command. lower()
is a function in SQL, not Ruby, which will return the single string parameter as a lowercase string. It's the equivilent of .downcase
in Ruby. Now that both the original string and the string to compare are lowercase, the case no longer matters.