2012-03-07 9 views
2

Railsでアクティブレコードの関連付けについて質問があります。 私は3つのアクティブレコードモデルを開発しています:チーム、Teamuser、ユーザー、 "has_many through"関連のテスト。 基本的に、私はteam.usersとuser.teamsを呼び出せるようにしたいだけです。ここアソシエーションを介してhas_manyの初期化されていない定数エラー

は、私はこの

team.usersを試してみてください、私のモデルは

team.rb 
    ####### 
    class Team < ActiveRecord::Base 

    has_many :teamusers, :foreign_key => :team_id 
    has_many :users, :through => :teamusers 

    end 

、その後

teamuser.rb 
    ########### 
    class Teamuser < ActiveRecord::Base 

    belongs_to :teams 
    belongs_to :users 

    end 

user.rb 
    ######## 
    class User < ActiveRecord::Base 

    has_many :teamusers, :foreign_key => :user_id 
    has_many :teams, :through => :teamusers 

    end 

たび定義です

「初期化されていない定数Team :: Users」というエラーが返されます。

私は何が間違っていますか? アドバイスをいただければ幸いです。

答えて

5

あなたTeamuserは次のようになります。

class Teamuser < ActiveRecord::Base 

    belongs_to :team 
    belongs_to :user 
end 
関連する問題