Sha256: 56338751877843837fa432d4b73ca055c1368bbcf56dcedebbeec4e98b091ae8

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryDocuments
    class SectionSuggestionsController < Decidim::ParticipatoryDocuments::ApplicationController
      include FormFactory
      include Paginable

      helper_method :section, :suggestions
      layout false

      def index
        @form = form(Decidim::ParticipatoryDocuments::SuggestionForm).instance
      end

      def create
        @form = form(Decidim::ParticipatoryDocuments::SuggestionForm).from_params(params)

        CreateSuggestion.call(@form, section) do
          on(:ok) do |_suggestion|
            redirect_to(document_section_suggestions_path(document, section.id)) && return
          end
          on(:invalid) do
            render template: "decidim/participatory_documents/section_suggestions/index", format: [:html], status: :bad_request
          end
        end
      end

      private

      def suggestions
        @suggestions ||= section.suggestions.where(author: current_user).order(created_at: :asc)
      end

      def section
        @section ||= document.sections.find(params[:section_id])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-participatory_documents-0.2.0 app/controllers/decidim/participatory_documents/section_suggestions_controller.rb