Class: Decidim::Debates::DebatesController

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

Overview

Exposes the debate resource so users can view them

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods inherited from Components::BaseController

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

Methods included from RegistersPermissions

register_permissions

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#default_locale?

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#closeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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