アソシエーションで検索し、黒点で検索するにはどうすればよいですか?
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
モデルを検索するとビジネス名がポップアップ表示されるようにするにはどうすればよいですか?
ありがとう