Sha256: 51d38abee81399af50b5e9490c2e93bf6eb08624510fd78dbc3f85693ed8b1ac

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # Exposes the line items resource so users can create and remove from orders.
    class LineItemsController < Decidim::Budgets::ApplicationController
      include NeedsCurrentOrder

      helper_method :project

      def create
        authorize_action! "vote"

        respond_to do |format|
          AddLineItem.call(current_order, project, current_user) do
            on(:ok) do |order|
              self.current_order = order
              format.html { redirect_to :back }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: 422
            end
          end
        end
      end

      def destroy
        respond_to do |format|
          RemoveLineItem.call(current_order, project) do
            on(:ok) do |_order|
              format.html { redirect_to :back }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: 422
            end
          end
        end
      end

      private

      def project
        @project ||= Project.find_by(id: params[:project_id], component: current_component)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-budgets-0.13.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.12.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.13.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.12.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.13.0.pre1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.12.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.11.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.12.0.pre app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.11.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.11.0.pre1 app/controllers/decidim/budgets/line_items_controller.rb