2011-11-18 11 views
0

私は現在、次のモデルがあります:私は例外を取得なぜhas_manyを使用するとカントレール3が私の関連付けを見つけるのですか?

<%= @team.users %> 

フロントエンドに

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 

そして、私は次のようにします。

は関連を見つけることができませんでした:選手モデルチーム

そして、私がしようとすると:#

起きても何の任意の手がかりのための

未定義のメソッド '選手':

<%= @team.players %> 

私は次を得ますか?

答えて

2

私はあなたにもそう

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 
のように、あなたの参加モデルを含める必要が信じています
関連する問題