Class: Decidim::Surveys::SurveysController

Inherits:
ApplicationController show all
Includes:
FormFactory
Defined in:
app/controllers/decidim/surveys/surveys_controller.rb

Overview

Exposes the survey resource so users can view and answer them.

Instance Method Summary collapse

Instance Method Details

#answerObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/decidim/surveys/surveys_controller.rb', line 15

def answer
  enforce_permission_to :answer, :survey

  @form = form(SurveyForm).from_params(params)

  AnswerSurvey.call(@form, current_user, survey) do
    on(:ok) do
      flash[:notice] = I18n.t("surveys.answer.success", scope: "decidim.surveys")
      redirect_to survey_path(survey)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("surveys.answer.invalid", scope: "decidim.surveys")
      render action: "show"
    end
  end
end

#showObject



11
12
13
# File 'app/controllers/decidim/surveys/surveys_controller.rb', line 11

def show
  @form = form(SurveyForm).from_model(survey)
end