views:

20

answers:

1

Hello,

I am learning Rails and have created a work-in-progress app that does one-word searches on a database of shortcut keys for various programs (http://keyboardcuts.heroku.com/shortcuts/home). The search method in the Shortcut model is the following:

def self.search(search)
  search_condition = "%" + search + "%"
  find(:all, :conditions => ['action LIKE ? OR application LIKE ?', search_condition, search_condition])
end

...where 'action' and 'application' are columns in a SQLite table. (source: https://we.riseup.net/rails/simple-search-tutorial)

For some reason, the search seems to be case sensitive (you can see this by searching 'Paste' vs. 'paste'). Can anyone help me figure out why and what I can do to make it not case sensitive? If not, can you at least point me in the right direction?

Database creation: I first copied shortcuts from various website into Excel and saved it as a CSV. Then I migrated the database and filled it with the data using db:seed and a small script I wrote (I viewed the database and it looked fine). To get the SQLite database to the server, I used Taps as outline by the Heroku website (http://blog.heroku.com/archives/2009/3/18/push_and_pull_databases_to_and_from_heroku/). I am using Ubuntu.

Please let me know if you need more information. Thanks in advance for you help, very much appreciated!

Ryan

A: 

Rather than change any settings in the db, you can just use SQL functions to force data to lowercase, then change you search_condition accordingly:

def self.search(search)
  search_condition = "%" + search.downcase + "%"
  find(:all, :conditions => ['LOWER(action) LIKE ? OR LOWER(application) LIKE ?', search_condition, search_condition])

end

Toby Hede