Sha256: 156fd207db94b243c578f6e580d2f1406393d97e85a76f37650b78dea45cba2b

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

module CitizenBudgetModel
  class QuestionsController < CitizenBudgetModelController
    before_action :authenticate_user!
    before_action :set_simulator
    before_action :set_section
    before_action :set_question, only: [:show, :edit, :update, :destroy]

    def show
    end

    def new
      @question = collection.new
    end

    def edit
    end

    def create
      @question = collection.new(question_params)

      if @question.save
        redirect_to [@simulator, @section, @question], notice: _('Question was created.')
      else
        render :new
      end
    end

    def update
      if @question.update(question_params)
        redirect_to [@simulator, @section, @question], notice: _('Question was updated.')
      else
        render :edit
      end
    end

    def destroy
      @question.destroy
      redirect_to [@simulator, @section], notice: _('Question was deleted.')
    end

  private

    def collection
      @collection ||= @section.questions
    end

    def set_simulator
      @simulator = simulators.find(params[:simulator_id])
    end

    def set_section
      @section = @simulator.sections.find(params[:section_id])
    end

    def set_question
      @question = collection.find(params[:id])
    end

    def question_params
      attribute_names = Question.globalize_attribute_names + [:machine_name, :default_value, :unit_value, :account, :widget, :options, :revenue, :maxlength, :required, :rows, :cols, :size, :html_class, :minimum, :maximum, :step, :labels_as_list, :options_as_list]
      params.require(:question).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/questions_controller.rb