Skip to content

Instantly share code, notes, and snippets.

@sebyx07
Created June 25, 2014 19:14
Show Gist options
  • Save sebyx07/70d1ab554978a0485f26 to your computer and use it in GitHub Desktop.
Save sebyx07/70d1ab554978a0485f26 to your computer and use it in GitHub Desktop.
#controller
def create
@party = Party.new(party_params)
@party.captain_id = @user.id
if @party.save
@user.join_party(@party)
respond_to do |format|
format.html { redirect_to @party, notice: 'Party was successfully created.' }
format.json { render :show, status: :created, location: @party }
end
else
respond_to do |format|
format.html { render :new }
format.json { render json: @party.errors, status: :unprocessable_entity }
end
end
end
#method from model
def join_party(party)
if self.online?
self.update(current_party_id: party.id)
self.join_party
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment