如何通过关联搜索和通过太阳黑子搜索?
class StaticController < ApplicationController
def search
@search = Sunspot.search Business, Service do
fulltext params[:q]
paginate :per_page => 10
order_by_geodist(:location, *Geocoder.coordinates(params[:loc]))
end
@biz = @search.results
end
class Business < ActiveRecord::Base
attr_accessible :name
has_many :services, :through => :professionals
searchable do
text :name #name in business column
# how to do I get the services?
end
end
class Service < ActiveRecord::Base
attr_accessible :service
belongs_to :professional
end
class Professional < ActiveRecord::Base
belongs_to :business
has_many :services, as: :servicable
end
在视图中,我有这个(很多循环)
<%= @biz.each do |b| %>
<%= b.name %>
<!-- looping through professionals model -->
<% b.professionals.each do |prof| %>
<!-- looping through services model -->
<% prof.services.each do |s| %>
<%= s.service %>
<% end %>
<% end %>
<% end %>
如果我搜索业务模型中的名称,这很有效,但如果我搜索Service
模型中的术语怎么办?它不会正确显示,因为我的观点仅来自业务方面。Service
如果我通过模型搜索,我该如何做才能弹出公司名称?
谢谢