A
A
Anton2016-02-04 20:27:34
Ruby on Rails
Anton, 2016-02-04 20:27:34

How to make a query case insensitive?

news = News.arel_table
query_string = "%#{params[:text]}%"
@news = News.where(news[:title].matches(query_string))

The passed values ​​"Title" and "Title" are different. If the first is found, then the second is not. How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Z0nd0R, 2016-02-04
@Z0nd0R

For Postgres, you can do something like this:

query_string = UnicodeUtils.upcase(params[:text], :ru)
@news = News.where('UPPER(news.title) LIKE ?', "%#{query_string}%")

And don't forget to add the corresponding index

G
g_s_e, 2016-02-04
@g_s_e

i did this user = User.where("lower(email) = ?", params[:email].downcase).first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question