我創建了一個有多個類別(如體育,歷史,藝術等)的瑣事遊戲。在每個類別的比賽結束時,我只想爲該單個類別顯示結果的記分牌。從Rails控制器調用單個方法
通過指定的方法類,我現在僅成功地過濾了歷史成績,爲在這裏看到:
class ScoreboardController < ApplicationController
def index
@participations = Participation.where(finished: true, category: "history").order(score: :desc)
end
end
雖然那好,我現在需要讓這個記分板控制器爲歷史,運動和任何其他數量的類別迭代產生過濾後的一組分數,而它僅涵蓋當前的歷史分類。
要做到這一點,我試圖創建控制器內的第二種方法爲:
@participations = Participation.where(finished: true, category: "sports").order(score: :desk)
不幸的是,這仍然只是沒有體育成績返回得分第一方法的歷史。
我覺得我做的兩件事情錯了:
1)我是不是通過增加額外的迭代到相同的控制器寫入方法不正確?
2)在的記分板視圖(而不是記分板控制器),我沒有正確調用控制器。
任何想法我錯了嗎?
附加信息:記分牌查看
<thead>
<tr>
<th>#</th>
<th>User</th>
<th>Category</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<% @participations.each_with_index do |participation, index| %>
<tr>
<td>#<%= index + 1 %></td>
<td><%= participation.user.username %></td>
<td><%= participation.category %></td>
<td><%= participation.score %></td>
</tr>
<% end %>
</tbody>
請發表您的控制器代碼,而不僅僅是網頁摘要 – Tim
@Tim - 這是記分牌合作上面的ntroller代碼。您是否要求參考模型? – darkginger