Class: Decidim::ReportsController

Inherits:
ApplicationController show all
Includes:
FormFactory, NeedsPermission
Defined in:
app/controllers/decidim/reports_controller.rb

Overview

Exposes the report resource so users can report a reportable.

Instance Method Summary collapse

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

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 'app/controllers/decidim/reports_controller.rb', line 11

def create
  enforce_permission_to :create, :moderation

  @form = form(Decidim::ReportForm).from_params(params)

  CreateReport.call(@form, reportable, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("decidim.reports.create.success")
      redirect_back fallback_location: root_path
    end

    on(:invalid) do
      flash[:alert] = I18n.t("decidim.reports.create.error")
      redirect_back fallback_location: root_path
    end
  end
end