forked from fixin.me/fixin.me
Display form errors using custom validity messages
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user