forked from fixin.me/fixin.me
Improve controllers and views
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
class UnitsController < ApplicationController
|
||||
before_action only: :new do
|
||||
find_unit if params[:id].present?
|
||||
end
|
||||
before_action :find_unit, only: [:edit, :update, :rebase, :destroy]
|
||||
before_action ->{ @unit = current_user.units.find_by!(id: params[:id]) },
|
||||
only: [:new, :edit, :update, :rebase, :destroy],
|
||||
unless: ->{ action_name == "new" && params[:id].nil? }
|
||||
|
||||
before_action except: :index do
|
||||
before_action except: [:index] do
|
||||
raise AccessForbidden unless current_user.at_least(:active)
|
||||
end
|
||||
|
||||
@@ -20,7 +19,7 @@ class UnitsController < ApplicationController
|
||||
@unit = current_user.units.new(params.expect(Unit::ATTRIBUTES))
|
||||
if @unit.save
|
||||
@before = @unit.successive
|
||||
flash.now[:notice] = t('.success', unit: @unit)
|
||||
flash.now.notice = t('.success', unit: @unit)
|
||||
else
|
||||
render_errors @unit
|
||||
end
|
||||
@@ -31,7 +30,7 @@ class UnitsController < ApplicationController
|
||||
|
||||
def update
|
||||
if @unit.update(params.except(:base_id).expect(Unit::ATTRIBUTES))
|
||||
flash.now[:notice] = t('.success', unit: @unit)
|
||||
flash.now.notice = t('.success', unit: @unit)
|
||||
else
|
||||
render_errors @unit
|
||||
end
|
||||
@@ -48,18 +47,14 @@ class UnitsController < ApplicationController
|
||||
|
||||
@before = @unit.successive
|
||||
if @unit.multiplier_previously_changed?
|
||||
flash.now[:notice] = t(".multiplier_reset", unit: @unit)
|
||||
flash.now.notice = t(".multiplier_reset", unit: @unit)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@unit.destroy!
|
||||
flash.now[:notice] = t('.success', unit: @unit)
|
||||
flash.now.notice = t('.success', unit: @unit)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_unit
|
||||
@unit = current_user.units.find_by!(id: params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user