I need to do two associations in the same model. Where:
Team has_many
User
Now, I want that Team has_one
Leader
This "Leader" will be a User
Im trying to use has_one throught
but I think that association isn't work.
Leader.rb
class Leader < ActiveRecord::Base
belongs_to :user
belongs_to :team
Team.rb
class Team < ActiveRecord::Base
has_one :user, through: :leader
end
User.rb
class User < ActiveRecord::Base
belongs_to :team
has_one :captain
end
and the get following error around line 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)