嗨,我创建了两个模型,
class Fixture < ActiveRecord::Base
attr_accessible :away_score, :away_team_id, :home_score, :home_team_id, :result, :week
belongs_to :team, :class_name => Team
end
class Team < ActiveRecord::Base
attr_accessible :form, :name
has_many :fixtures, :class_name => Fixture, :foreign_key => :home_team_id
has_many :fixtures, :class_name => Fixture, :foreign_key => :away_team_id
end
在我的灯具表中,我将 team_id 存储在 home_team_id 和 away_team_id 列中。
然后在我的 fixtures/show.html.erb 中显示存储的 id
<p>
<b>Home team:</b>
<%= @fixture.home_team_id %>
</p>
如何通过将 team.id 存储在夹具表中来显示团队表中的 team.name?
我需要将此行 <%= @fixture.home_team_id %> 更改为其他内容,但不确定是什么?