views:

24

answers:

1

When I run Book.scoped({:conditions => ['books.index LIKE ?','%query%']}) I get:

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "index": syntax error: SELECT * FROM "books" WHERE (books.index like '%query%')

What am I doing wrong?

+2  A: 

Credit goes to Adam Bernier for pointing out that index is a SQL keyword (cf. comment on question). I am reposting the solution here so that this question gets marked as answered.

While

Book.scoped({:conditions => ['`index` LIKE ?','%query%']})

works, for peace of mind, I decided to rename the column.

Nicholas H.