Class: Decidim::Surveys::Admin::SurveysController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Surveys::Admin::SurveysController
- Includes:
- Filterable
- Defined in:
- app/controllers/decidim/surveys/admin/surveys_controller.rb
Overview
This controller allows to index, create, update, destroy, publish and unpublish a Survey.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 20 def create (:create, :questionnaire) @form = form(Admin::SurveyForm).from_params(params) Decidim::Surveys::Admin::CreateSurvey.call(current_component, @form) do on(:ok) do |survey| flash[:notice] = I18n.t("create.success", scope: "decidim.surveys.admin.surveys") redirect_to edit_survey_path(survey) end on(:invalid) do flash.now[:alert] = I18n.t("create.invalid", scope: "decidim.surveys.admin.surveys") render action: "new", status: :unprocessable_entity end end end |
#destroy ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 89 def destroy (:destroy, :questionnaire, questionnaire: survey) Decidim::Commands::DestroyResource.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("destroy.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end end end |
#edit ⇒ Object
37 38 39 40 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 37 def edit (:update, :questionnaire, questionnaire: survey) @form = form(Admin::SurveyForm).from_model(survey) end |
#index ⇒ Object
12 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 12 def index; end |
#new ⇒ Object
14 15 16 17 18 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 14 def new (:create, :questionnaire) @form = form(Admin::SurveyForm).instance end |
#publish ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 59 def publish (:update, :questionnaire, questionnaire: survey) Decidim::Surveys::Admin::PublishSurvey.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("publish.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end on(:invalid) do flash.now[:alert] = I18n.t("publish.invalid", scope: "decidim.surveys.admin.surveys") render action: "index", status: :unprocessable_entity end end end |
#unpublish ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 74 def unpublish (:update, :questionnaire, questionnaire: survey) Decidim::Surveys::Admin::UnpublishSurvey.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("unpublish.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end on(:invalid) do flash.now[:alert] = I18n.t("unpublish.invalid", scope: "decidim.surveys.admin.surveys") render action: "index", status: :unprocessable_entity end end end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 42 def update (:update, :questionnaire, questionnaire: survey) @form = form(Admin::SurveyForm).from_params(params) Admin::UpdateSurvey.call(@form, survey, current_user) do on(:ok) do flash[:notice] = I18n.t("update.success", scope: "decidim.surveys.admin.surveys") redirect_to edit_survey_path(survey) end on(:invalid) do flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.surveys.admin.surveys") render action: "edit", status: :unprocessable_entity end end end |