-
Notifications
You must be signed in to change notification settings - Fork 25
/
roles_controller.rb
56 lines (45 loc) · 1.08 KB
/
roles_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
# frozen_string_literal: true
class RolesController < ApplicationController
before_action :set_role, only: %i[show edit update destroy]
# GET /roles
def index
@roles = Role.all
end
# GET /roles/new
def new
@role = Role.new
end
# GET /roles/1/edit
def edit; end
# POST /roles
def create
@role = Role.new(role_params)
if @role.save
redirect_to roles_url, notice: "Role was successfully created."
else
render :new
end
end
# PATCH/PUT /roles/1
def update
if @role.update(role_params)
redirect_to roles_url, notice: "Role was successfully updated."
else
render :edit
end
end
# DELETE /roles/1
def destroy
@role.destroy
redirect_to roles_url, notice: "Role was successfully destroyed."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_role
@role = Role.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def role_params
params.require(:role).permit(:name, permissions_attributes: {})
end
end