Class: Strongbolt::RolesController
- Inherits:
-
StrongboltController
- Object
- StrongboltController
- Strongbolt::RolesController
- Defined in:
- app/controllers/strongbolt/roles_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 27 def create @role = Role.create! role_params flash[:success] = 'Role was successfully created!' redirect_to role_path(@role) rescue ActiveRecord::RecordInvalid flash[:danger] = 'Role could not be created, please review the errors below' redirect_to new_role_path rescue ActionController::ParameterMissing => e flash[:danger] = "Role could not be created: ERROR #{e}" redirect_to new_role_path rescue ActiveRecord::ActiveRecordError flash[:danger] = 'The parent you selected leads to an impossible configuration' redirect_to edit_role_path(@role) end |
#destroy ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 60 def destroy @role = Role.find params[:id] @role.destroy! flash[:success] = "Role #{@role.name} successfully deleted" redirect_to roles_path rescue ActiveRecord::DeleteRestrictionError flash[:danger] = "Role #{@role.name} could not be deleted because #{@role.user_groups.size} user groups rely on it" redirect_to role_path(@role) end |
#edit ⇒ Object
23 24 25 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 23 def edit @role = Role.find params[:id] end |
#index ⇒ Object
3 4 5 6 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 3 def index @roles = Role.includes(:parent) .order('parent_id IS NOT NULL', 'parent_id', 'name') end |
#new ⇒ Object
8 9 10 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 8 def new @role = Role.new end |
#show ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 12 def show @role = Role.find params[:id] @capabilities = @role.capabilities.to_hash @inherited_capabilities = @role.inherited_capabilities.to_hash # All the models we have @keys = (@capabilities.keys | @inherited_capabilities.keys) @descendants = @role.descendants end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/strongbolt/roles_controller.rb', line 43 def update @role = Role.find params[:id] @role.update_attributes! role_params flash[:success] = 'Role was successfully updated!' redirect_to role_path(@role) rescue ActiveRecord::RecordInvalid flash[:danger] = 'Role could not be updated, please review the errors below' redirect_to edit_role_path(@role) rescue ActionController::ParameterMissing => e flash[:danger] = "Role could not be updated: ERROR #{e}" redirect_to edit_role_path(@role) rescue ActiveRecord::ActiveRecordError flash[:danger] = 'The parent you selected leads to an impossible configuration' redirect_to edit_role_path(@role) end |