Sha256: 5af046ffaf6d474883b7766f8c646e0ee51c91d6c40cdb0128a2973ac6075f81

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module CitizenBudgetModel
  class SimulatorsController < CitizenBudgetModelController
    before_action :authenticate_user!
    before_action :set_simulator, only: [:show, :edit, :update, :destroy, :activate, :sort]

    def index
      @simulators = collection.all.sort_by(&:name)
    end

    def show
    end

    def new
      @simulator = collection.new
    end

    def edit
    end

    def create
      @simulator = collection.new(simulator_params)

      if @simulator.save
        redirect_to @simulator, notice: _('Simulator was created.')
      else
        render :new
      end
    end

    def update
      if @simulator.update(simulator_params)
        redirect_to @simulator, notice: _('Simulator was updated.')
      else
        render :edit
      end
    end

    def destroy
      @simulator.destroy
      redirect_to simulators_path, notice: _('Simulator was deleted.')
    end

    def activate
      @simulator.activate!
      redirect_to @simulator, notice: _('Simulator was activated.')
    end

    def sort
      super(@simulator.sections)
    end

  private

    def collection
      @collection ||= simulators
    end

    def set_simulator
      @simulator = collection.find(params[:id])
    end

    def simulator_params
      attribute_names = Simulator.globalize_attribute_names + [:equation]
      if admin?
        attribute_names << :organization_id
      end
      params.require(:simulator).permit(*attribute_names)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
citizen_budget_model-0.0.1 app/controllers/citizen_budget_model/simulators_controller.rb