简体   繁体   中英

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

尝试

where("LOWER (description) LIKE ? OR LOWER (title) LIKE ?", "%#{search.downcase}%" , "%#{search.downcase}%")

I had this problem, too. Heroku uses PostgreSQL and the LIKE-Operator there is strongly typed to strings. Check this http://www.postgresql.org/docs/8.3/interactive/functions-matching.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM