Class: Decidim::Budgets::LineItemsController

Inherits:
ApplicationController show all
Includes:
NeedsCurrentOrder
Defined in:
decidim-budgets/app/controllers/decidim/budgets/line_items_controller.rb

Overview

Exposes the line items resource so users can create and remove from orders.

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_workflow, #show_votes_count?, #voting_finished?, #voting_open?

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #share_token

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-budgets/app/controllers/decidim/budgets/line_items_controller.rb', line 11

def create
  enforce_permission_to :vote, :project, project: project, budget: budget, workflow: current_workflow

  respond_to do |format|
    AddLineItem.call(persisted_current_order, project, current_user) do
      on(:ok) do |order|
        self.current_order = order
        format.html { redirect_back(fallback_location: budget_path(budget)) }
        format.js { render "update_budget" }
      end

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

#destroyObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-budgets/app/controllers/decidim/budgets/line_items_controller.rb', line 29

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

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