diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 1426fca..87c67ea 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -19,7 +19,7 @@ class UnitsController < ApplicationController def create @unit = current_user.units.new(unit_params) if @unit.save - flash.now[:notice] = t(".success") + flash.now[:notice] = t('.success', unit: @unit) run_and_render :index else render :new @@ -31,7 +31,7 @@ class UnitsController < ApplicationController def update if @unit.update(unit_params.except(:base_id)) - flash.now[:notice] = t(".success") + flash.now[:notice] = t('.success', unit: @unit) run_and_render :index else render :edit @@ -40,18 +40,21 @@ class UnitsController < ApplicationController def rebase permitted = params.require(:unit).permit(:base_id) - if permitted[:base_id].blank? && @unit.multiplier != 1 - permitted.merge!(multiplier: 1) + permitted.merge!(multiplier: 1) if permitted[:base_id].blank? && @unit.multiplier != 1 + + @unit.update!(permitted) + + if @unit.multiplier_previously_changed? flash.now[:notice] = t(".multiplier_reset", unit: @unit) end - - run_and_render :index if @unit.update(permitted) + ensure + run_and_render :index end def destroy - if @unit.destroy - flash.now[:notice] = t(".success") - end + @unit.destroy! + flash.now[:notice] = t('.success', unit: @unit) + ensure run_and_render :index end diff --git a/config/locales/en.yml b/config/locales/en.yml index fe127bb..31dd9a9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -63,13 +63,13 @@ en: new: none: none create: - success: Created new unit + success: Created new unit "%{unit}" update: - success: Updated unit + success: Updated unit "%{unit}" rebase: multiplier_reset: Multiplier of "%{unit}" has been reset to 1, due to repositioning destroy: - success: Deleted unit + success: Deleted unit "%{unit}" default: units: unit: