School
モデルとモデルの2つのモデルがありPrice
ます。すべての学校には価格があります。今は欲しい結果が返ってきましたが、学校の最高価格と最低価格を並べ替える並べ替え関数を実装したいと思います。
学校の管理者:
class SchoolsController < ApplicationController
def index
@query = params[:search]
@search = School.search(:include => [:price] do
fulltext params[:search]
paginate :page => params[:page], :per_page => 7
end
@results = @search.results
end
end
学校モデル:
class School < ActiveRecord::Base
has_one :price
# sunspot search
searchable do
text :name, :locality
end
end
インデックス-表示
<ul>
# Cheapest price
<li><span class="label label-ord">Show cheapest price <%= @query %></span></li>
# Highest price
<li><span class="label label-ord">Show highest price <%= @query %></span></li>
</ul>
<% for result in @results %>
<tr>
# School name, from the school-model
<td><h3><%= link_to result.name, result %></h3></td>
# School price, from the price-model
<td><h3><%= result.prices.min %> kr</h3></td>
</tr>
<% end %>
どうすれば最高価格と最低価格を並べ替えることができますか。ファセットまたはメソッドを使用する必要がありますか?それ、どうやったら出来るの?