Class: Decidim::Debates::DebatesController

Inherits:
ApplicationController show all
Includes:
Orderable, FilterResource, Flaggable, FormFactory, Paginable
Defined in:
app/controllers/decidim/debates/debates_controller.rb

Overview

Exposes the debate resource so users can view them

Instance Method Summary collapse

Instance Method Details

#closeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/decidim/debates/debates_controller.rb', line 70

def close
  enforce_permission_to(:close, :debate, debate:)

  @form = form(CloseDebateForm).from_params(params)

  CloseDebate.call(@form) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.close.success", scope: "decidim.debates")
      redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash[:alert] = I18n.t("debates.close.invalid", scope: "decidim.debates")
      redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
    end
  end
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/decidim/debates/debates_controller.rb', line 24

def create
  enforce_permission_to :create, :debate

  @form = form(DebateForm).from_params(params)

  CreateDebate.call(@form) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.create.success", scope: "decidim.debates")
      redirect_to Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.create.invalid", scope: "decidim.debates")
      render action: "new"
    end
  end
end

#editObject



46
47
48
49
50
# File 'app/controllers/decidim/debates/debates_controller.rb', line 46

def edit
  enforce_permission_to(:edit, :debate, debate:)

  @form = form(DebateForm).from_model(debate)
end

#newObject



18
19
20
21
22
# File 'app/controllers/decidim/debates/debates_controller.rb', line 18

def new
  enforce_permission_to :create, :debate

  @form = form(DebateForm).instance
end

#showObject

Raises:

  • (ActionController::RoutingError)


42
43
44
# File 'app/controllers/decidim/debates/debates_controller.rb', line 42

def show
  raise ActionController::RoutingError, "Not Found" if debate.blank?
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/decidim/debates/debates_controller.rb', line 52

def update
  enforce_permission_to(:edit, :debate, debate:)

  @form = form(DebateForm).from_params(params)

  UpdateDebate.call(@form, debate) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.update.success", scope: "decidim.debates")
      redirect_to Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.update.invalid", scope: "decidim.debates")
      render :edit
    end
  end
end