怎么做has_one通过?

时间:2015-04-07 20:51:15

标签: ruby-on-rails

我正在尝试进行此关联,其中:

小组has_one用户through队长

Captain.rb

class Captain < ActiveRecord::Base
belongs_to :user
belongs_to :team

Team.rb

class Team < ActiveRecord::Base
has_one :user, through: :captain
end

User.rb

class User < ActiveRecord::Base

has_one :captain
belongs_to :team
has_many :invites
has_and_belongs_to_many :games
has_one :captain

end

以及第27行的以下错误:

NoMethodError in TeamsController#create

26 def create
*27 @team = current_user.teams.create(team_params)*
28 @team.save
29 respond_with(@team)
30 current_user.update(team_id: @team.id)

...谢谢

0 个答案:

没有答案