Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL syntax in Rails 3, NOT Case sensitive searching, not working on Heroku?

I've been following the Railscast for adding searching, sorting, and pagination to my app. I've modified my search logic in the model to search to columns (description and title). This seems to be working. I've also changed it to search non case sensitive. This seems to work perfect in my local app, but when I push it to heroku, I can only search by lowercase. Search with any capital letters at all produces no results, even if the case matches the results.

here is the code in my model:

  def self.search(search)
    if search
      where('LOWER (description) LIKE ? OR LOWER (title) LIKE ?', "%#{search}%" , "%#{search}%")
    else
      scoped
    end
  end
like image 531
Elliot Avatar asked Jan 12 '11 18:01

Elliot


1 Answers

Try

where("LOWER (description) LIKE ? OR LOWER (title) LIKE ?", "%#{search.downcase}%" , "%#{search.downcase}%")
like image 143
David Sulc Avatar answered Sep 22 '22 00:09

David Sulc