我就知道让谁拥有了搜索结果的产品的所有用户的最佳方式获得的搜索产品的用户搜索结果
我控制器
@users = User.all // i must change here ?
if params[:product_type].present? && params[:location].present? && params[:discount].present?
@products = Product.near(params[:location], 1, units: :km).where(product_type: params[:product_type], discount: params[:discount])
end
我的观点
<% @products.each do |p| %>
<%= p.user.company_name %>
<% end %>
我方法的工作,但如果一个公司有2个产品它的显示它2次
可能就像在_p.users.uniq.company_name_上调用_.uniq_一样简单,但需要查看模型和关联以确认。 –