Ruby on rails 显示页面上未初始化的常量RubyonRails有多个关联

Ruby on rails 显示页面上未初始化的常量RubyonRails有多个关联,ruby-on-rails,ruby,associations,Ruby On Rails,Ruby,Associations,我有以下协会,一个球队有很多球员,一个球员有一个球队 球员正在工作,我可以在球队页面上列出他们,但是,我不能在球员展示页面上列出球队。下面是模型和代码 class Player < ApplicationRecord has_rich_text :bio has_one_attached :photo has_one :team_players has_one :team, through: :team_players end 显示页面 <p> <s

我有以下协会,一个球队有很多球员,一个球员有一个球队

球员正在工作,我可以在球队页面上列出他们,但是,我不能在球员展示页面上列出球队。下面是模型和代码

class Player < ApplicationRecord
  has_rich_text :bio
  has_one_attached :photo
  has_one :team_players
  has_one :team, through: :team_players
end
显示页面

<p>
  <strong>Team:</strong>
  <%= @player.team.name %>
</p>
Rails控制台结果

irb(main):005:0> Player.all
  Player Load (0.5ms)  SELECT "players".* FROM "players" LIMIT $1  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Player id: 1, ign: "NadeShot", name: "Matthew Haag", role: "CEO", twitch_link: "hhh", twitter_link: "hhh", instagram_link: "hhh", games_played: 200, games_won: 100, games_lost: 100, win_percentage: 50, character: "NadeShot", created_at: "2020-06-02 14:59:31", updated_at: "2020-06-02 21:13:05", country: "US", estimated_earnings: 100000>]>
irb(main):006:0> TeamPlayer.all
  TeamPlayer Load (0.4ms)  SELECT "team_players".* FROM "team_players" LIMIT $1  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<TeamPlayer id: 1, player_id: 1, team_id: 1, created_at: "2020-06-04 17:49:46", updated_at: "2020-06-04 17:49:46">]>
改为单数:

class Player < ApplicationRecord
  has_rich_text :bio
  has_one_attached :photo
  has_one :team_player # instead of team_players
  has_one :team, through: :team_player # instead of team_players
end

哪个控制器?节目里什么都没有,不应该有,因为有关联。我将更新以包括DB模式更新问题
irb(main):005:0> Player.all
  Player Load (0.5ms)  SELECT "players".* FROM "players" LIMIT $1  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Player id: 1, ign: "NadeShot", name: "Matthew Haag", role: "CEO", twitch_link: "hhh", twitter_link: "hhh", instagram_link: "hhh", games_played: 200, games_won: 100, games_lost: 100, win_percentage: 50, character: "NadeShot", created_at: "2020-06-02 14:59:31", updated_at: "2020-06-02 21:13:05", country: "US", estimated_earnings: 100000>]>
irb(main):006:0> TeamPlayer.all
  TeamPlayer Load (0.4ms)  SELECT "team_players".* FROM "team_players" LIMIT $1  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<TeamPlayer id: 1, player_id: 1, team_id: 1, created_at: "2020-06-04 17:49:46", updated_at: "2020-06-04 17:49:46">]>
class Player < ApplicationRecord
  has_rich_text :bio
  has_one_attached :photo
  has_one :team_player # instead of team_players
  has_one :team, through: :team_player # instead of team_players
end