/
abuse_report_statuses_controller.rb
58 lines (48 loc) · 1.32 KB
/
abuse_report_statuses_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
class AbuseReportStatusesController < ApplicationController
before_action :verify_core, except: [:index, :show]
before_action :set_status, except: [:index, :create]
before_action :verify_admin, only: :destroy
def index
@statuses = AbuseReportStatus.all
end
def create
@status = AbuseReportStatus.new status_params
if @status.save
flash[:success] = 'Created status.'
redirect_back fallback_location: abuse_status_path(@status)
else
flash[:danger] = 'Failed to create status.'
redirect_to abuse_statuses_path
end
end
def show
@reports = @status.reports.includes(:contact, :status, :user)
end
def edit; end
def update
if @status.update status_params
flash[:success] = 'Updated status.'
redirect_to abuse_status_path(@status)
else
flash[:danger] = 'Failed to update.'
render :edit
end
end
def destroy
if @status.destroy
flash[:success] = 'Removed status.'
redirect_to abuse_statuses_path
else
flash[:danger] = 'Failed to remove.'
redirect_to abuse_status_path(@status)
end
end
private
def set_status
@status = AbuseReportStatus.find params[:id]
end
def status_params
params.require(:abuse_report_status).permit(:name, :details, :icon, :color)
end
end