I am using SQLite3 for development and PostgreSQL for deployment. However, I am facing the following problem:
My simple search using SQLite3
:
def self.search(search)
if search
find(:all, :conditions => ["style LIKE ? OR construction LIKE ?", "%#{search}%", "%#{search}%"])
else
find(:all)
end
end
However, it doesn't work for PostgreSQL
, and I need to replace the LIKE
for ILIKE
to solve the problem:
def self.search(search)
if search
find(:all, :conditions => ["style ILIKE ? OR construction ILIKE ?", "%#{search}%", "%#{search}%"])
else
find(:all)
end
end
Is there a "Ruby way" to do these searches across any database?
EDIT - based on your answers I don't believe I will find a generic Ruby solution for that.
I have followed the Ruby on Rails Tutorial: Learn Rails by Example - by Michael Hartl, where the final Gemfile shows both databases... well, disappointing...
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…