現在、Diablo 3 のオークションを追跡するアプリを作成していますが、並べ替えに問題があります。
現在、すべてのアイテムと最新のセールに関する情報を一覧表示するアイテム ページがあります。どの商品も複数のセールを行うことができますが、最新のセールのみを商品ページに表示したいと考えています。
すべてが正しく表示されており、アイテム モデルに属しているため、アイテム NAME、GEARSLOT、および iLVL で問題なく並べ替えることができます。
ただし、販売通貨または価格で並べ替えるのは難しいことがわかっています。これを調べたところ、各アイテムの販売が 1 つしかない場合に適用できる解決策がたくさん見つかりましたが、最新の関連付けだけで並べ替えるのに役立つものは何もありませんでした.
index.html.erb
<table id="item_list">
<tr class="header_row">
<th><%= link_to "Name", :sort => :name %></th>
<th><%= link_to "Gearslot", :sort => :gearslot %></th>
<th><%= link_to "Ilvl", :sort => :ilvl %></th>
<th>Currency</th>
<th>Price</th>
</tr>
<% @items.each do |item| %>
<% last_sale = item.sales.find(:last) %>
<tr>
<td><%= item.name %></td>
<td><%= item.Gearslot %></td>
<td><%= item.iLvl %></td>
<td><%= Sale::CURRENCYCODE.index(last_sale.currency) %></td>
<td><%= last_sale.price %></td>
</tr>
....
items_controller.rb
def index
@items = Item.order(params[:sort])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @items }
end
end
そもそもこれが最も効果的な方法ではない可能性があることはすでにわかっているので、アドバイスをいただければ幸いです。