mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 04:55:20 +02:00
Handle correctly turbo_stream request format
This commit is contained in:
parent
62d6efcb93
commit
4087275751
2 changed files with 52 additions and 45 deletions
|
@ -24,12 +24,13 @@ class CategoriesController < ApplicationController
|
||||||
|
|
||||||
redirect_target_url = request.referer || categories_path
|
redirect_target_url = request.referer || categories_path
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_back_or_to categories_path, notice: t(".success") }
|
|
||||||
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
set_categories
|
set_categories
|
||||||
render :new, status: :unprocessable_entity
|
respond_to do |format|
|
||||||
|
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,10 +39,15 @@ class CategoriesController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @category.update(category_params)
|
if @category.update(category_params)
|
||||||
|
flash[:notice] = t(".success")
|
||||||
|
|
||||||
redirect_back_or_to categories_path, notice: t(".success")
|
respond_to do |format|
|
||||||
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, categories_path) }
|
||||||
|
end
|
||||||
else
|
else
|
||||||
render :edit, status: :unprocessable_entity
|
respond_to do |format|
|
||||||
|
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<%# locals: (category:, categories:) %>
|
<%# locals: (category:, categories:) %>
|
||||||
|
<%= turbo_frame_tag 'form' do %>
|
||||||
<div data-controller="color-avatar">
|
<div data-controller="color-avatar">
|
||||||
<%= styled_form_with model: category, class: "space-y-4", data: { turbo_frame: :_top } do |f| %>
|
<%= styled_form_with model: category, class: "space-y-4" do |f| %>
|
||||||
<section class="space-y-4">
|
<section class="space-y-4">
|
||||||
<div class="w-fit m-auto">
|
<div class="w-fit m-auto">
|
||||||
<%= render partial: "shared/color_avatar", locals: { name: category.name, color: category.color } %>
|
<%= render partial: "shared/color_avatar", locals: { name: category.name, color: category.color } %>
|
||||||
|
@ -46,3 +46,4 @@
|
||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
Loading…
Add table
Add a link
Reference in a new issue