I have a model, Game, that has_many :teams. There’s a home team and an
away team. I created two foreign keys, so each game can have two teams
associated with it. Here’s the Team model:
class Team < ActiveRecord::Base
:class_name => ‘Game’, :foreign_key => ‘hometeam_id’
:class_name => ‘Game’, :foreign_key => ‘visitingteam_id’
Now, assuming that works correctly, how do I use those associations in
my view. Let’s say I want to show the names of the teams in a game.
Doing something like this doesn’t work: <%= game.team.name %> because it
doesn’t specify which team I’m asking for. How do I differentiate
between them when I want to display them in a view?