forked from fixin.me/fixin.me
Update error handling according to new rules
This commit is contained in:
parent
2cbae12fa2
commit
13685aa476
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user