Reputation: 7339
I'm struggling with associations today.
I have 2 models
User
Match
A match is initiated by a userA and has an opponent, userB
I need to be able to distinguish which user created the match and which is the opposer so simple has_many
& belongs_to
isn't enough.
Upvotes: 1
Views: 69
Reputation: 4575
Ok i would do something like this:
on my create Match action i would create the match like this
Match controller:
def create
@match= Match.new(params[:match])
@match.creator_id = current_user.id
respond_to do |format|
if @match.save
format.html
else
format.html
end
end
end
asuming you are using something like devise and that the match model has both of the users and one is the creator_id
Upvotes: 1