1

I am trying to use joins in rails to retrieve some info base on a search field but I cannot seem to find the good syntax, I have two table savings and product and saving are saving for a product. What I want is to find a saving based on the name of the product I found that this work : Saving.all(:joins => :product, :conditions => { :products => { :title => 'Title Name' } }) It retrieve the saving corresponding to the product named Title Name.

Now how can I change that to find the savings where product title contains params[:title] ?

Thanks,

Jeremy B
  • 911
  • 7
  • 20

2 Answers2

2
Saving.joins(:product).where('products.title like ?', "%#{params[:title]}%")
aromero
  • 25,681
  • 6
  • 57
  • 79
  • Thanks, now i'm trying to do that with squeel so I did that : Saving.joins{product}.where{savings.products.title =~ my{params[:term]} } which is working with the full title but I don't know how to make the request work with part of the title name. thanks – Jeremy B Sep 28 '12 at 09:41
1
Saving.joins{product}.where{(savings.products.title =~ my{"%#{params[:term]}%"} } with squeel
Jeremy B
  • 911
  • 7
  • 20