結果を追加・編集するフォームがあれば表示したい。n * n のテーブルがあります。ここで、セル内のチームの数は結果によって与えられます。これはどのように最適ですか?
view/championship/show.erb
<table class="table table-bordered">
<tr><th> </th>
<% @teams.each do |teamhome| %>
<th class="vertical"><%= teamhome.name %></th>
<% end %>
</tr>
<% @teams.each do |teamguest| %>
<tr>
<th><%= teamguest.name %></th>
<% @teams.each do |teamhome| %>
<%if teamhome == teamguest %>
<td bgcolor = '#F9F9F9'>
<% else %>
<td>
#render form
</td>
<% end %>
<% end %>
</tr>
<% end %>
</table>
モデル
class Score < ActiveRecord::Base
attr_accessible :team1_score, :team2_score, :team1_id, :team2_id, :team1, :team2
belongs_to :team1, class_name: 'Team', foreign_key: :team1_id
belongs_to :team2, class_name: 'Team', foreign_key: :team2_id
def self.to_arr
score_arr = self.find(:all, :select => 'team1_id, team2_id, team1_score, team2_score').to_a
end
end
class Team < ActiveRecord::Base
attr_accessible :name
belongs_to :championship
has_many :team1_scores, class_name: 'Score', foreign_key: :team1_id
has_many :team2_scores, class_name: 'Score', foreign_key: :team2_id
validates :name, presence: true, length: { maximum: 100 }
validates :championship_id, presence: true
end
スキーマ
"team1_id"|"team2_id"|"team1_score"|"team2_score"