forked from openware/barong
/
labels_controller.rb
52 lines (41 loc) · 1.06 KB
/
labels_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
# frozen_string_literal: true
module Admin
class LabelsController < ModuleController
before_action :find_account
before_action :find_label, only: %i[edit update destroy]
def new
@label = @account.labels.new
end
def create
@label = @account.labels.new(label_params)
if @label.save
redirect_to admin_account_path(@account), notice: 'Label was successfully created.'
else
render :new
end
end
def edit
end
def update
if @label.update(label_params)
redirect_to admin_account_path(@account), notice: 'Label was successfully updated.'
else
render :edit
end
end
def destroy
@label.destroy!
redirect_to admin_account_path(@account), notice: 'Label was successfully destroyed.'
end
private
def find_account
@account = Account.find(params[:account_id])
end
def find_label
@label = @account.labels.find(params[:id])
end
def label_params
params.require(:label).permit(:key, :value, :scope)
end
end
end