Created
June 25, 2014 19:14
-
-
Save sebyx07/70d1ab554978a0485f26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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