Render units from collection, without redirects

This commit is contained in:
2024-01-15 18:45:30 +01:00
parent de995aa586
commit 5047d4909f
9 changed files with 37 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ class UnitsController < ApplicationController
raise AccessForbidden unless current_user.at_least(:active)
end
before_action only: [:edit, :update, :destroy] do
raise ArgumentError unless current_user == @unit.user
raise ParameterInvalid unless current_user == @unit.user
end
def index
@@ -20,7 +20,7 @@ class UnitsController < ApplicationController
@unit = current_user.units.new(unit_params)
if @unit.save
flash[:notice] = t(".success")
@units = current_user.units
run_and_render :index
else
render :new
end
@@ -32,7 +32,7 @@ class UnitsController < ApplicationController
def update
if @unit.update(unit_params)
flash[:notice] = t(".success")
redirect_to units_url
run_and_render :index
else
render :edit
end
@@ -42,7 +42,7 @@ class UnitsController < ApplicationController
if @unit.destroy
flash[:notice] = t(".success")
end
redirect_to units_url
run_and_render :index
end
private