Sha256: a964f91b940fcfc668de07640d465302518d174bcad4a9d57a48d9574bbc7838
Contents?: true
Size: 1.59 KB
Versions: 54
Compression:
Stored size: 1.59 KB
Contents
# frozen_string_literal: true module Decidim module Surveys module Admin # This controller allows the user to update a Page. class SurveysController < Admin::ApplicationController helper_method :survey, :blank_question, :blank_answer_option, :question_types def edit authorize! :edit, Survey @form = form(Admin::SurveyForm).from_model(survey) end def update authorize! :update, Survey params["published_at"] = Time.current if params.has_key? "save_and_publish" @form = form(Admin::SurveyForm).from_params(params) Admin::UpdateSurvey.call(@form, survey) do on(:ok) do flash[:notice] = I18n.t("surveys.update.success", scope: "decidim.surveys.admin") redirect_to parent_path end on(:invalid) do flash.now[:alert] = I18n.t("surveys.update.invalid", scope: "decidim.surveys.admin") render action: "edit" end end end private def survey @survey ||= Survey.find_by(feature: current_feature) end def blank_question @blank_question ||= survey.questions.build(body: {}, answer_options: []) end def blank_answer_option @blank_answer_option ||= OpenStruct.new(body: {}) end def question_types @question_types ||= SurveyQuestion::TYPES.map do |question_type| [question_type, I18n.t("decidim.surveys.question_types.#{question_type}")] end end end end end end
Version data entries
54 entries across 54 versions & 2 rubygems