0
得到了視圖和控制器驗證碼:滑軌從視圖中移動查詢到控制器
# matches/show.html.haml
%h3
Players
[email protected] do |clan|
%h4=link_to clan.name, clan
%ul
[email protected]_all_by_clan_id(clan.id).each do |player|
%li
%strong=link_to player.name, player
%h3
[email protected]_with_index do |round,index|
%h4
Round
=index+1
[email protected] do |clan|
%h4=clan.name
%ul
-round.participations.includes(:player,:champion).find_all_by_clan_id(clan.id).each do |participation|
%li
=participation.player.name
=participation.champion.name
# matches_controller.rb
class MatchesController < ApplicationController
def index
@matches = Match.played.includes(:clans).page(params[:page])
end
def show
@match = Match.includes(:rounds,:clans).find(params[:id])
@clans = @match.clans
@rounds = @match.rounds
@players = @match.players
end
end
如何移動所有不必要的數據庫查詢,邏輯等,從視圖控制器?
也許簡化這個莫名其妙?