I’m a newbie to rails. I’ve done a search query
myresult = Model1.includes(':model2', ':model3').where("model1.field1 LIKE ? OR model1. field2 LIKE ? OR model2.field1 LIKE ? OR model2.field2 LIKE ? OR model2.field3 LIKE ? OR model3.field1 LIKE ? " value1, value1, value2, value2, value3, value4 ).select("model1.field1, ..., model1.fieldn, model2.field1.., model3.field2 ")
Now I hear this is not a good practice. Other one I found is someone said to use joins of Arel. But Arel seems to be relatively new and for me it looked like SQL-injection prone. Can some one suggest a good way of doing this in ruby on rails.
Thank you
Sai
If you’re trying to do full-text search across several fields, you don’t want to do this in SQL.
You should use a speciallized full text search system like Sphinx or Solr.
Check out Thinking Sphinx (Rails Sphinx API):
http://freelancing-god.github.com/ts/en/