Permalink
Browse files

Cleaned roles.

  • Loading branch information...
1 parent fd1f00d commit ed355d4c1099de459d33c3d540476db51bd0ccfc @raskhadafi raskhadafi committed Feb 18, 2011
Showing with 23 additions and 2 deletions.
  1. +1 −1 app/models/ability.rb
  2. +21 −0 db/migrate/20110217150538_clean_up_roles.rb
  3. +1 −1 db/schema.rb
View
@@ -8,7 +8,7 @@ class Ability
# Available roles
def self.roles
- ['admin', 'pupil', 'teacher']
+ ['admin', 'student', 'teacher']
end
# Prepare roles to show in select inputs etc.
@@ -0,0 +1,21 @@
+class CleanUpRoles < ActiveRecord::Migration
+ def self.up
+ admins = User.all.select{|user| user.role?('admin')}
+ students = User.all.select{|user| user.role?('student')}
+ teachers = User.all.select{|user| user.role?('teacher')}
+
+ Role.delete_all
+ execute "DELETE FROM roles_users"
+
+ admin = Role.create(:name => 'admin')
+ student = Role.create(:name => 'student')
+ teacher = Role.create(:name => 'teacher')
+
+ admins.map{|user| user.roles << admin; user.save}
+ students.map{|user| user.roles << student; user.save}
+ teachers.map{|user| user.roles << teacher; user.save}
+ end
+
+ def self.down
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101214084946) do
+ActiveRecord::Schema.define(:version => 20110217150538) do
create_table "addresses", :force => true do |t|
t.string "post_office_box", :limit => 50

0 comments on commit ed355d4

Please sign in to comment.