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
 | 
					  def create
 | 
				
			||||||
    @unit = current_user.units.new(unit_params)
 | 
					    @unit = current_user.units.new(unit_params)
 | 
				
			||||||
    if @unit.save
 | 
					    if @unit.save
 | 
				
			||||||
      flash.now[:notice] = t(".success")
 | 
					      flash.now[:notice] = t('.success', unit: @unit)
 | 
				
			||||||
      run_and_render :index
 | 
					      run_and_render :index
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      render :new
 | 
					      render :new
 | 
				
			||||||
@ -31,7 +31,7 @@ class UnitsController < ApplicationController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def update
 | 
					  def update
 | 
				
			||||||
    if @unit.update(unit_params.except(:base_id))
 | 
					    if @unit.update(unit_params.except(:base_id))
 | 
				
			||||||
      flash.now[:notice] = t(".success")
 | 
					      flash.now[:notice] = t('.success', unit: @unit)
 | 
				
			||||||
      run_and_render :index
 | 
					      run_and_render :index
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      render :edit
 | 
					      render :edit
 | 
				
			||||||
@ -40,18 +40,21 @@ class UnitsController < ApplicationController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def rebase
 | 
					  def rebase
 | 
				
			||||||
    permitted = params.require(:unit).permit(:base_id)
 | 
					    permitted = params.require(:unit).permit(:base_id)
 | 
				
			||||||
    if permitted[:base_id].blank? && @unit.multiplier != 1
 | 
					    permitted.merge!(multiplier: 1) if permitted[:base_id].blank? && @unit.multiplier != 1
 | 
				
			||||||
      permitted.merge!(multiplier: 1)
 | 
					
 | 
				
			||||||
 | 
					    @unit.update!(permitted)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if @unit.multiplier_previously_changed?
 | 
				
			||||||
      flash.now[:notice] = t(".multiplier_reset", unit: @unit)
 | 
					      flash.now[:notice] = t(".multiplier_reset", unit: @unit)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					  ensure
 | 
				
			||||||
    run_and_render :index if @unit.update(permitted)
 | 
					    run_and_render :index
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def destroy
 | 
					  def destroy
 | 
				
			||||||
    if @unit.destroy
 | 
					    @unit.destroy!
 | 
				
			||||||
      flash.now[:notice] = t(".success")
 | 
					    flash.now[:notice] = t('.success', unit: @unit)
 | 
				
			||||||
    end
 | 
					  ensure
 | 
				
			||||||
    run_and_render :index
 | 
					    run_and_render :index
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -63,13 +63,13 @@ en:
 | 
				
			|||||||
    new:
 | 
					    new:
 | 
				
			||||||
      none: none
 | 
					      none: none
 | 
				
			||||||
    create:
 | 
					    create:
 | 
				
			||||||
      success: Created new unit
 | 
					      success: Created new unit "%{unit}"
 | 
				
			||||||
    update:
 | 
					    update:
 | 
				
			||||||
      success: Updated unit
 | 
					      success: Updated unit "%{unit}"
 | 
				
			||||||
    rebase:
 | 
					    rebase:
 | 
				
			||||||
      multiplier_reset: Multiplier of "%{unit}" has been reset to 1, due to repositioning
 | 
					      multiplier_reset: Multiplier of "%{unit}" has been reset to 1, due to repositioning
 | 
				
			||||||
    destroy:
 | 
					    destroy:
 | 
				
			||||||
      success: Deleted unit
 | 
					      success: Deleted unit "%{unit}"
 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
    units:
 | 
					    units:
 | 
				
			||||||
      unit:
 | 
					      unit:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user