Skip to content

Commit

Permalink
Render updated total costs as stream when expense destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Oct 9, 2023
1 parent 125eecf commit c07ae4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/controllers/fixed_expenses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ def update
# DELETE /fixed_expenses/1 or /fixed_expenses/1.json
def destroy
@fixed_expense.destroy
@totals = FixedExpense.total_costs
@fixed_expenses = FixedExpense.get_ordered
respond_to do |format|
format.html { redirect_to fixed_expenses_path, notice: "Fixed expense was successfully destroyed." }
format.turbo_stream { render turbo_stream: turbo_stream.remove(@fixed_expense) }
# format.turbo_stream { render turbo_stream: turbo_stream.remove(@fixed_expense) }
format.turbo_stream
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/views/fixed_expenses/destroy.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_stream.remove @fixed_expense %>

<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { totals: @totals } %>
<% end %>

0 comments on commit c07ae4f

Please sign in to comment.