Class: Decidim::Lausanne::Budgets::LineItemsController

Inherits:
ApplicationController
  • Object
show all
Includes:
NeedsCurrentOrder
Defined in:
app/controllers/decidim/lausanne/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_user_record, #current_workflow, #show_votes_count?, #voting_finished?, #voting_open?

Instance Method Details

#createObject



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

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: lausanne_budget_path(budget)) }
        format.js { render "update_budget" }
      end

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

#destroyObject



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

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

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