You can do the following:
Product.includes(:producer)
.where('products.name LIKE ? OR producers.name LIKE ?', "%#{params[:q]}%", "%#{params[:q]}%")
You can make a scope with it:
class Product < ActiveRecord::Base
scope :with_name_like, lambda { |name|
includes(:producer).where('products.name LIKE ? OR producers.name LIKE ?', "%#{name}%", "%#{name}%")
}
And use it like this:
@products = Product.with_name_like('Chair')