Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么rails 3在使用has\u多时找不到我的关联?_Ruby On Rails - Fatal编程技术网

Ruby on rails 为什么rails 3在使用has\u多时找不到我的关联?

Ruby on rails 为什么rails 3在使用has\u多时找不到我的关联?,ruby-on-rails,Ruby On Rails,我目前有以下型号: class Player < ActiveRecord::Base belongs_to :team belongs_to :user end class Team < ActiveRecord::Base has_many :users, :through => :players end class User < ActiveRecord::Base has_many :teams, :through => :player

我目前有以下型号:

class Player < ActiveRecord::Base
  belongs_to :team
  belongs_to :user
end

class Team < ActiveRecord::Base
  has_many :users, :through => :players

end

class User < ActiveRecord::Base
  has_many :teams, :through => :players
end
classplayer:玩家
结束
类用户:球员
结束
当我在前端执行以下操作时

<%= @team.users %>

我得到一个例外:

找不到关联:模型团队中的玩家

当我尝试时:

<%= @team.players %>

我得到以下信息:

未定义的方法“玩家”#


有什么线索吗?

我相信您还需要包括您的加入模型,就像这样

class Player < ActiveRecord::Base
  belongs_to :team
  belongs_to :user
end

class Team < ActiveRecord::Base
  has_many :players
  has_many :users, :through => :players

end

class User < ActiveRecord::Base
  has_many :players
  has_many :teams, :through => :players
end
classplayer:玩家
结束
类用户:球员
结束