R
R
Roman Volkov2015-06-09 08:27:24
Ruby on Rails
Roman Volkov, 2015-06-09 08:27:24

How to do case insensitive searches in Rails?

I use the following construction where('lower(name) LIKE ?', "%#{name}.downcase)%"), but for some reason downcase doesn't work and gives out the string I entered

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Viktor Vsk, 2015-06-09
@white_wolf_17

Horrible.
1. See the resulting query (interpolation does not work).
2. Use ILIKE instead of manually doing everything.
3. What is the base?

T
timoo, 2015-06-09
@tomcat1911

downcase does not work with Cyrillic, you can do this:str.mb_chars.downcase

J
Jeiwan, 2015-06-09
@Jeiwan

Well, you have an error in the code:
where('lower(name) LIKE ?', "%#{name}.downcase)%") - the query will be "WHERE lower(name) LIKE '%Name.downcase)%'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question