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:玩家
结束
类用户:球员
结束