Html 找不到名为的关联

Html 找不到名为的关联,html,ruby-on-rails,Html,Ruby On Rails,我在互联网上搜索过,但由于某些原因,这些答案很接近,但对我没有帮助 所以我有一张球员表和一张球队表。一名球员可以属于多个球队。一支球队可以有很多球员 以下是我的模型: Liveplayer: class LivePlayer < ActiveRecord::Base has_many :teamplayers has_many :fteams, :through => :teamplayers end class Fteam < ActiveRecord::Base belo

我在互联网上搜索过,但由于某些原因,这些答案很接近,但对我没有帮助

所以我有一张球员表和一张球队表。一名球员可以属于多个球队。一支球队可以有很多球员

以下是我的模型: Liveplayer

class LivePlayer < ActiveRecord::Base
has_many :teamplayers
has_many :fteams, :through => :teamplayers
end
class Fteam < ActiveRecord::Base
belongs_to :liveplayer
end
class Teamplayer < ActiveRecord::Base
belongs_to :live_player
belongs_to :fteam
end
class-LivePlayer:团队成员
终止
Fteam

class LivePlayer < ActiveRecord::Base
has_many :teamplayers
has_many :fteams, :through => :teamplayers
end
class Fteam < ActiveRecord::Base
belongs_to :liveplayer
end
class Teamplayer < ActiveRecord::Base
belongs_to :live_player
belongs_to :fteam
end
类Fteam 团队成员

class LivePlayer < ActiveRecord::Base
has_many :teamplayers
has_many :fteams, :through => :teamplayers
end
class Fteam < ActiveRecord::Base
belongs_to :liveplayer
end
class Teamplayer < ActiveRecord::Base
belongs_to :live_player
belongs_to :fteam
end

class Teamplayer
这些表格的名称分别是live_玩家和FTEAM

以下是html:

<select id = "test4" style= float:left>
<% Teamplayer.includes(:live_player).all do |tp| %>
    <option> <%=tp.id %></option>  <- This returns nothing right now
<% end %>
</select>


属于\u的对象通常是单数的,特别是因为您的模型是单数的。如果类是驼峰式的,则使用破折号

belongs_to :live_player
另外,看起来TeamPlayer是一个连接表,其他类应该与之关联。例如

class LivePlayer < ActiveRecord::Base
  has_many :team_players
  has_many :fteams, :through => :team_players
end
class-LivePlayer:团队成员
终止
fteam上是否有球队球员id?如果是这样的话,那是属于谁的——也许是队长或球队创建者?如果是这样的话,您将得到如下结果:

class Fteam < ActiveRecord::Base
   belongs_to :live_player
   has_many :team_players
   has_many :live_players, :through => :team_players
end
类Fteam:团队球员 终止
在表单中,要获取团队ID,您可能需要使用fteam而不是team_player-它不会有重复项

<% Fteam.all do |t| %>
    <option> <%= t.id %></option>
<% end %>


Teamplayer类的代码
class?
class Teamplayer
此外,此行不会在控制台中运行:
Teamplayer.includes(:live\u-player)。all
它给出关联错误:在Teamplayer中找不到关联live\u-player。查看模型更新了解一些进展,现在我得到了这个:未初始化的常量Teamplayer::LivePlayerswell!哪一行?这一行:有人能告诉我为什么下面这一行给出了关联错误:Teamplayer.includes(:live\u player)。在Teamplayer上未找到名为“live_player”的关联;也许你拼错了?请参阅上面的模型,因为它们已更新,所以“所属对象”:live玩家是Teamplayer中应该包含的内容?是的,teamplayer是一个包含两个字段playerid和teamid的联接表。Fteam没有teamplayer id。对于表单,如果我想将团队加载到列表中,那么我可以使用Fteam id执行此操作?`'返回nothingYes-teamplayer应该属于:live\u player。您可能希望在控制台中测试所有这些
rails c
并尝试Fteam.all查看数据库中的内容。还有,什么Rails版本?我在控制台中使用了Fteam.all并得到了返回值。当我执行Fteam.find_each时,它会在html中返回值,但Fteam.all在html中不会返回任何值,请改为尝试此操作。