Ruby On Rails : Case insensitive matching in Rails .where() clause

Its very easy to perform case insensitive searches in Rails as well as any SQL queries. SQL some useful functions to do so. Either you can UpCase or DownCase both the operands to perform such searching operations.

Comment.where("LOWER(comments.comment) LIKE LOWER('%test%')")
Comment.where('lower(name) = lower(?)',

using the above example may hamper the portability of your application as function in different SQLs may vary. The example below is recommended

comments = Comment.arel_table

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s