I'm fairly new to rails and I'm trying to figure out the best way to do this.
I have a players table and a teams table. They both are HABTM with each other and use a join table.
Models
class Player < ActiveRecord::Base
has_and_belongs_to_many :teams
end
class Team < ActiveRecord::Base
has_and_belongs_to_many :players
end
Controller
def players
@players = Player.all
end
View
<%@players.each do |player|%>
<tr>
<td><%= link_to "Add", "steam://friends/add/#{player.steamid}"%></td>
<td><%= link_to player.name, player%></td>
<td><%=player.email%></td>
<td><%=player.teams.teamname%></td>
</tr>
<%end%>
First, I know teamname should be team_name.
I've tried building a loop that loops through the teams but this page has over 1600 players and so it takes a few minutes to run it.
Am I missing a better way to do this?