From 975dd39ec8665b22c7f6decb172482b34944b439 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 25 Sep 2020 10:55:13 -0700 Subject: [PATCH] Update parties_controller.rb Finding parties based on shortcode, and saving parties with user ID where available --- app/controllers/api/v1/parties_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 442f1b6..1107f13 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -6,11 +6,12 @@ class Api::V1::PartiesController < Api::V1::ApiController end def create - @party = Party.new(shortcode: random_string) + @party = Party.new(shortcode: random_string, user_id: party_params[:user_id]) render :show, status: :created if @party.save! end def show + render_not_found_response if @party.nil? end def update @@ -28,6 +29,10 @@ class Api::V1::PartiesController < Api::V1::ApiController end def set - @party = Party.find("abc") + @party = Party.where("shortcode = ?", params[:id]).first + end + + def party_params + params.require(:party).permit(:user_id) end end \ No newline at end of file