Q:

Question about Association and Models on Rails

I have been working on a project recently where a Player can create a Team and be the Team Owner, but a player as well can be part of the Team by a separate table, named Squad.
class Player
has_many :teams
has_many :squads
end

class Squad
belongs_to :player
belongs_to :team
end

class Team
belongs_to :owner, :class_name => "Player"
has_many :squads
has_many :players, :through => "squads"
end

I don't know if this is all I need to make what I want, but I just can't figure out. How can I make the player ask to be invited to the team via Squad, and the Owner of the Team answers yes or no to that player? If yes, he joins table Squad and is part of the team. If no, his request is destroyed.

A:

You need to make a boolean field status in your Squad model, that defaults to false. If you need something more complex, you could use this gem.
So player invokes a squad#create action, it creates a squad model. 
Team#show shows the owner of the team join requests from players and use squad#accept or squad#reject (or #update with status argument) and then you change the status to true, or destroy this squad record.
And basically that's it
Updated
This is how a basic social network friending system works. 
With state_machine you could define another state rejected, so the same user doesn't spam the team owner with requests after being rejected. By checking the updated_at field, you could implement a timeout, after which the same person could repeat his request.

