Boolean conditions in Rails find statements
I was having trouble getting a condition set on a standard find query. I had a table with a boolean column and was expecting to do something like this
a = model.find(:all, :conditions => 'checked = true')
But that (and variations on it) didn’t work, a bit of searching turned up a suitable solution here: http://snippets.dzone.com/posts/show/2086 included below for future reference:
a = model.find(:all, :conditions => ['checked = ?', true])
That generates the correct SQL for whatever database back end your using.