Created
February 23, 2012 09:41
-
-
Save azuby/1891965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Permissions | |
| permission = [] | |
| [ | |
| { action: "create", resource: "User", access: "none" }, | |
| { action: "read", resource: "User", access: "individual" }, | |
| { action: "update", resource: "User", access: "individual" }, | |
| { action: "destroy", resource: "User", access: "individual" }, | |
| { action: "create", resource: "Shift", access: "none" }, | |
| { action: "read", resource: "Shift", access: "individual" }, | |
| { action: "update", resource: "Shift", access: "individual" }, | |
| { action: "destroy", resource: "Shift", access: "individual" }, | |
| { action: "create", resource: "Job", access: "none" }, | |
| { action: "read", resource: "Job", access: "company" }, | |
| { action: "update", resource: "Job", access: "company" }, | |
| { action: "destroy", resource: "Job", access: "company" } | |
| ].each_with_index do |params, i| | |
| permission[i] = Permission.where(params).first_or_create! | |
| end | |
| # Roles | |
| [ | |
| { name: "Administrator", permission_ids: [2, 6, 8, 9, 10, 11, 12] }, | |
| { name: "Supervisor", permission_ids: [2, 6, 10] }, | |
| { name: "Basic", permission_ids: [6] } | |
| ].each do |params| | |
| role = Role.where( name: params[:name] ).first_or_create! | |
| params[:permission_ids].each do |permission_id| | |
| puts permission[permission_id].inspect #this works | |
| role.privileges.create!( permission_id: permission[permission_id].object_id ) #this throws the error below | |
| end | |
| end | |
| # Error: gems/activerecord-3.2.0/lib/active_record/validations.rb:56:in `save!': Validation failed: Permission can't be blank (ActiveRecord::RecordInvalid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment