diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index ea9e769..d47f42f 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -33,9 +33,26 @@ def create location_id: @location.id ) else - flash[:error_save_review] = "Couldn't save your review" - - render :new + respond_to do |format| + format.html do + flash[:error_save_review] = "Couldn't save your review" + + render :new + end + + format.turbo_stream do + flash.now[:error_save_review] = "Couldn't save your review" + + render turbo_stream: turbo_stream.replace( + "review-form", + partial: "reviews/shared/form", + locals: { + location: @location, + review: @review + } + ) + end + end end end @@ -62,9 +79,26 @@ def update location_id: @location.id ) else - flash[:error_save_review] = "Couldn't save your review" - - render :new + respond_to do |format| + format.html do + flash[:error_save_review] = "Couldn't save your review" + + render :edit + end + + format.turbo_stream do + flash.now[:error_save_review] = "Couldn't save your review" + + render turbo_stream: turbo_stream.replace( + "review-form", + partial: "reviews/shared/form", + locals: { + location: @location, + review: @review + } + ) + end + end end end diff --git a/app/views/reviews/shared/_form.html.erb b/app/views/reviews/shared/_form.html.erb index b04f622..1d45552 100644 --- a/app/views/reviews/shared/_form.html.erb +++ b/app/views/reviews/shared/_form.html.erb @@ -1,140 +1,142 @@ -<% if flash[:error_save_review].present? %> -