mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-03 20:45:21 +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
|
||||
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) }
|
||||
end
|
||||
else
|
||||
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
|
||||
|
||||
|
@ -38,10 +39,15 @@ class CategoriesController < ApplicationController
|
|||
|
||||
def update
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<%# locals: (category:, categories:) %>
|
||||
|
||||
<div data-controller="color-avatar">
|
||||
<%= styled_form_with model: category, class: "space-y-4", data: { turbo_frame: :_top } do |f| %>
|
||||
<%= turbo_frame_tag 'form' do %>
|
||||
<div data-controller="color-avatar">
|
||||
<%= styled_form_with model: category, class: "space-y-4" do |f| %>
|
||||
<section class="space-y-4">
|
||||
<div class="w-fit m-auto">
|
||||
<%= render partial: "shared/color_avatar", locals: { name: category.name, color: category.color } %>
|
||||
|
@ -45,4 +45,5 @@
|
|||
<%= f.submit %>
|
||||
</section>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
Loading…
Add table
Add a link
Reference in a new issue