From 4ac38c35097399ee1a86cd83678e5c1f0c0bf32b Mon Sep 17 00:00:00 2001 From: Laura Mosher <2660801+lauramosher@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:34:49 -0400 Subject: [PATCH] fix: Creating or Updating a story without attaching media (#979) This fix checks for media existence before attempting to loop and attach media. Co-authored-by: Laura Mosher --- rails/app/controllers/dashboard/stories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rails/app/controllers/dashboard/stories_controller.rb b/rails/app/controllers/dashboard/stories_controller.rb index 66ac22cd9..af12311da 100644 --- a/rails/app/controllers/dashboard/stories_controller.rb +++ b/rails/app/controllers/dashboard/stories_controller.rb @@ -24,7 +24,7 @@ def create @story = community_stories.new(story_params.except(:media)) if @story.save - story_params[:media].each do |media| + story_params[:media]&.each do |media| m = @story.media.create(media: media) end redirect_to @story @@ -45,7 +45,7 @@ def update @story = authorize community_stories.find(params[:id]) if @story.update(story_params.except(:media)) - story_params[:media].each do |media| + story_params[:media]&.each do |media| m = @story.media.create(media: media) end