Question

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,

Was it helpful?

Solution 2

Saving.joins{product}.where{(savings.products.title =~ my{"%#{params[:term]}%"} } with squeel

OTHER TIPS

Saving.joins(:product).where('products.title like ?', "%#{params[:title]}%")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top