Class: Admin::RolesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::RolesController
- Defined in:
- app/controllers/admin/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
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 |
# File 'app/controllers/admin/roles_controller.rb', line 21 def create if params[:role] fp_params = params[:role].delete(:feature_permissions) || [] else fp_params = [] end @role = Role.new(params[:role]) @features = Feature.all success = false if success = @role.save fp_params.each do |fp| next if fp['feature_id'].blank? read_only = fp['read_only'] == fp['feature_id'] @role. << FeaturePermission.new(fp.merge(:role => @role, :read_only => read_only)) end success = @role.save end if success redirect_to(admin_role_url(@role), :notice => 'Role was successfully created.') else @role.destroy render :action => 'new' end end |
#destroy ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'app/controllers/admin/roles_controller.rb', line 82 def destroy return unless get_and_verify_role @role.destroy notice = 'Role was successfully deleted.' redirect_to(admin_roles_url, :notice => notice) end |
#edit ⇒ Object
16 17 18 19 |
# File 'app/controllers/admin/roles_controller.rb', line 16 def edit get_and_verify_role @features = Feature.all end |
#index ⇒ Object
3 4 5 |
# File 'app/controllers/admin/roles_controller.rb', line 3 def index @roles = Role.visible end |
#new ⇒ Object
11 12 13 14 |
# File 'app/controllers/admin/roles_controller.rb', line 11 def new @role = Role.new @features = Feature.all end |
#show ⇒ Object
7 8 9 |
# File 'app/controllers/admin/roles_controller.rb', line 7 def show get_and_verify_role end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/admin/roles_controller.rb', line 51 def update return unless get_and_verify_role if params[:role] fp_params = params[:role].delete(:feature_permissions) || [] else fp_params = [] end @features = Feature.all success = false if success = @role.update_attributes(params[:role]) @role.features = [] fp_params.each do |fp| next if fp['feature_id'].blank? read_only = fp['read_only'] == fp['feature_id'] @role. << FeaturePermission.new(fp.merge(:role => @role, :read_only => read_only)) end success = @role.save end if success redirect_to(admin_role_url(@role), :notice => 'Role was successfully updated.') else render :action => 'edit' end end |