Skip to content

Commit

Permalink
Cleaned roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
raskhadafi committed Feb 18, 2011
1 parent fd1f00d commit ed355d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/ability.rb
Expand Up @@ -8,7 +8,7 @@ class Ability


# Available roles # Available roles
def self.roles def self.roles
['admin', 'pupil', 'teacher'] ['admin', 'student', 'teacher']
end end


# Prepare roles to show in select inputs etc. # Prepare roles to show in select inputs etc.
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20110217150538_clean_up_roles.rb
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "addresses", :force => true do |t|
t.string "post_office_box", :limit => 50 t.string "post_office_box", :limit => 50
Expand Down

0 comments on commit ed355d4

Please sign in to comment.