Take the 2-minute tour ×

I currently have a model Books which stores details including the book's isbn.

I use this method to search for books (actually only using their ISBN's)

def self.search(search)
 search_condition = "%" + search.downcase + "%"
 find(:all, :conditions => ['(isbn LIKE ? OR lower(title) LIKE ? OR lower(author) LIKE ? OR lower(edition) LIKE ? OR lower(publisher) LIKE ?) AND removed_on IS NULL', search_condition, search_condition, search_condition, search_condition, search_condition])

What bothers me is that on my local machine, if I search "076374591X" I get all the books with that ISBN, but on my app on Heroku it does not return anything. I tried removing the "X" and only searching "076374591" and that works on both. It is as if the "X" in the ISBN breaks it (but only on the server).

Take note isbn is a :string.

What can possibly cause this issue, and how can I solve it?

share|improve this question
What version of ruby are you running on Heroku and on your local machine? Also, are you running postgres locally? –  Noah Clark Sep 18 '12 at 11:45
@NoahClark No, running SQLite locally and Postgres on heroku. Not sure about version, Local is newest version, I guess heroku too. –  LouwHopley Sep 18 '12 at 12:09
have you checked that the locale is the same in both environments? –  Will Palmer Sep 18 '12 at 12:21
if you do heroku version you will get the rails version you're running. If these are the same, I'd say it could be the way postgres is running the SQL statement. Might be worth looking at heroku logs and pasting the SQL statement into the question. –  Noah Clark Sep 18 '12 at 13:02
add comment

1 Answer

up vote 1 down vote accepted

You search by ISBN case-sensitive, but downcased search term first. So you should find "076374591x", but not "076374591X".

Try to lower isbn too:

find(:all, :conditions => ['(lower(isbn) LIKE ? OR lower(title) ...
share|improve this answer
I have tested both cases. It is saved in uppercase though. –  LouwHopley Sep 18 '12 at 12:18
If the book stored with isbn "076374591X" (uppercase) your search will find nothing since the search term is lowercased ("076374591X" -> "076374591x", "076374591x" -> "076374591x"). You have lowercased title, author, editor, etc. but not isbn. Try to lower it too. –  dimuch Sep 18 '12 at 12:40
Oooh! Sorry, I see you were correct. I missed the search.downcase and thought that entering the string with "x" and "X" would have different effect, although they're just being downcased. Thanks! –  LouwHopley Sep 18 '12 at 15:15
add comment

Your Answer


