Class: Admin::RolesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::RolesController
- Includes:
- TheRole::Controller
- Defined in:
- app/controllers/admin/roles_controller.rb
Instance Method Summary collapse
- #change ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #export ⇒ Object
- #import ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #role_export ⇒ Object
- #update ⇒ Object
Instance Method Details
#change ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/controllers/admin/roles_controller.rb', line 86 def change if @role.update_attributes!(role_params) flash = { notice: t(:role_updated, scope: t_scope) } redirect_to_edit flash else render action: :edit end end |
#create ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/roles_controller.rb', line 66 def create @role = Role.new role_params if @role.save flash = { notice: t(:role_created, scope: t_scope) } redirect_to_edit flash else render action: :new end end |
#destroy ⇒ Object
95 96 97 98 99 |
# File 'app/controllers/admin/roles_controller.rb', line 95 def destroy @role.destroy flash = { alert: t(:role_deleted, scope: t_scope) } redirect_to admin_roles_url, flash end |
#edit ⇒ Object
19 |
# File 'app/controllers/admin/roles_controller.rb', line 19 def edit; end |
#export ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/roles_controller.rb', line 34 def export roles = Role.all role_for_exports = roles.inject({}) do |hash, role| hash[role.name] = { title: role.title, description: role.description, role_hash: role.to_hash } hash end role_for_exports[:export_comment] = "EXPORT Roles: *#{ roles.map(&:name).join(', ') }*" send_data role_for_exports.to_json, filename: "TheRole_#{ roles.map(&:name).join('-') }.json" end |
#import ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/roles_controller.rb', line 50 def import roles_hash = params[:roles].try(:read) roles_hash = begin; JSON.parse roles_hash; rescue; {}; end roles_hash.except!('export_comment') flash = if roles_hash.keys.empty? { error: t(:cant_be_imported, scope: t_scope) } else roles_list = roles_hash.keys.join(', ') update_roles(roles_hash) { notice: t(:imported_roles, scope: t_scope, roles_list: roles_list) } end redirect_to admin_roles_url, flash: flash end |
#index ⇒ Object
11 12 13 |
# File 'app/controllers/admin/roles_controller.rb', line 11 def index @roles = Role.order('created_at ASC') end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/admin/roles_controller.rb', line 15 def new @role = Role.new end |
#role_export ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/admin/roles_controller.rb', line 21 def role_export role_for_export = { @role.name => { title: @role.title, description: @role.description, role_hash: @role.to_hash } } role_for_export[:export_comment] = "EXPORT Role with name: *#{ @role.name }*" send_data role_for_export.to_json, filename: "TheRole_#{ @role.name }.json" end |
#update ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'app/controllers/admin/roles_controller.rb', line 77 def update if @role.update_role params[:role][:the_role] flash = { notice: t(:role_updated, scope: t_scope) } redirect_to_edit flash else render action: :edit end end |