-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathroles_controller.rb
More file actions
62 lines (49 loc) · 1.38 KB
/
roles_controller.rb
File metadata and controls
62 lines (49 loc) · 1.38 KB
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
59
60
61
62
module Locomotive
class RolesController < BaseController
account_required & within_site
before_action :load_role, only: [:edit, :update, :destroy]
def new
authorize Role
@role = current_site.roles.build
respond_with @role
end
def create
authorize Role
if @role = service.create(role_params)
respond_with @role, location: edit_current_site_path(:anchor => "role"), flash: true
else
redirect_to new_role_path(current_site)
end
end
def edit
respond_with @role
end
def update
authorize @role
self.service.update(@role, role_params)
respond_with @role, location: edit_current_site_path(:anchor => "role")
end
def destroy
authorize @role
@role.destroy
respond_with @role, location: edit_current_site_path(:anchor => "role")
end
def new_model
if params[:role_model].present?
render partial: 'role_models', locals: { role_model: params[:role_model] }
else
head :unprocessable_entity
end
end
protected
def service
@service ||= Locomotive::RoleService.new(current_site, current_locomotive_account)
end
def load_role
@role = current_site.roles.find(params[:id])
end
def role_params
params.require(:role).permit(*policy(@role || Role).permitted_attributes)
end
end
end