diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ead4dda..ed1d867 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,6 +43,11 @@ class ApplicationController < ActionController::Base private + def render_no_content(record) + helpers.render_errors(record) + render html: nil, layout: true + end + def rescue_turbo(exception) raise unless request.format.to_sym == :turbo_stream diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index fe5213a..ab03865 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -43,7 +43,8 @@ class QuantitiesController < ApplicationController permitted = params.require(:quantity).permit(:parent_id) @previous_ancestors = @quantity.ancestors - @quantity.update!(permitted) + # Until UI blocks all disallowed reparents, render error messages if present + render_no_content(@quantity) unless @quantity.update(permitted) @ancestors = @quantity.ancestors @quantity.depth = @ancestors.length diff --git a/app/views/quantities/_quantity.html.erb b/app/views/quantities/_quantity.html.erb index c5d5d89..c3b14f6 100644 --- a/app/views/quantities/_quantity.html.erb +++ b/app/views/quantities/_quantity.html.erb @@ -2,8 +2,7 @@ ondragstart: "dragStart(event)", ondragend: "dragEnd(event)", ondragover: "dragOver(event)", ondrop: "drop(event)", ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)", - data: {drag_path: reparent_quantity_path(quantity), - drop_id: dom_id(quantity.parent || quantity), + data: {drag_path: reparent_quantity_path(quantity), drop_id: dom_id(quantity), drop_id_param: "quantity[parent_id]"} do %>