Display form errors using custom validity messages

This commit is contained in:
2026-07-28 00:45:08 +02:00
parent 5d051de666
commit eb2797bd90
13 changed files with 81 additions and 51 deletions

View File

@@ -55,9 +55,9 @@ class ApplicationController < ActionController::Base
private
def render_no_content(record)
helpers.render_errors(record)
render html: nil, layout: true
def render_errors(record)
target = record.new_record? ? [:new, record.parent || record.class] : [:edit, record]
render 'errors', assigns: {record: record, target: target}
end
def rescue_turbo(exception)

View File

@@ -43,12 +43,15 @@ class QuantitiesController < ApplicationController
permitted = params.require(:quantity).permit(:parent_id)
@previous_ancestors = @quantity.ancestors
# Until UI blocks all disallowed reparents, render error messages if present
render_no_content(@quantity) unless @quantity.update(permitted)
@ancestors = @quantity.ancestors
@self_and_progenies = @quantity.with_progenies
@before = @self_and_progenies.last.successive
if @quantity.update(permitted)
@ancestors = @quantity.ancestors
@self_and_progenies = @quantity.with_progenies
@before = @self_and_progenies.last.successive
else
# Until UI blocks all disallowed reparents, render error messages if present.
flash.now.alert = @quantity.errors.full_messages
render :nothing
end
end
def destroy

View File

@@ -22,7 +22,7 @@ class UnitsController < ApplicationController
@before = @unit.successive
flash.now[:notice] = t('.success', unit: @unit)
else
render :new
render_errors @unit
end
end
@@ -33,7 +33,7 @@ class UnitsController < ApplicationController
if @unit.update(params.except(:base_id).expect(Unit::ATTRIBUTES))
flash.now[:notice] = t('.success', unit: @unit)
else
render :edit
render_errors @unit
end
end