Description:
fix migration & model link bug in migration version 10 git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@91 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r42:0dae6922a01b - - 1 file changed: 7 inserted, 0 deleted

@@ -1,30 +1,37
1 class AddAdminAndRoles < ActiveRecord::Migration
1 class AddAdminAndRoles < ActiveRecord::Migration
2 +
3 +
2 def self.up
4 def self.up
3 root = User.new(:login => 'root',
5 root = User.new(:login => 'root',
4 :full_name => 'Administrator',
6 :full_name => 'Administrator',
5 :alias => 'root')
7 :alias => 'root')
6 root.password = 'ioionrails';
8 root.password = 'ioionrails';
9 +
10 + class << root
11 + public :encrypt_new_password
12 + end
13 +
7 root.encrypt_new_password
14 root.encrypt_new_password
8
15
9 role = Role.create(:name => 'admin')
16 role = Role.create(:name => 'admin')
10 root.roles << role;
17 root.roles << role;
11 root.save
18 root.save
12
19
13 user_admin_right = Right.create(:name => 'user_admin',
20 user_admin_right = Right.create(:name => 'user_admin',
14 :controller => 'user_admin',
21 :controller => 'user_admin',
15 :action => 'all')
22 :action => 'all')
16 problem_admin_right = Right.create(:name=> 'problem_admin',
23 problem_admin_right = Right.create(:name=> 'problem_admin',
17 :controller => 'problems',
24 :controller => 'problems',
18 :action => 'all')
25 :action => 'all')
19
26
20 role.rights << user_admin_right;
27 role.rights << user_admin_right;
21 role.rights << problem_admin_right;
28 role.rights << problem_admin_right;
22 role.save
29 role.save
23 end
30 end
24
31
25 def self.down
32 def self.down
26 admin_role = Role.find_by_name('admin')
33 admin_role = Role.find_by_name('admin')
27 admin_role.destroy unless admin_role==nil
34 admin_role.destroy unless admin_role==nil
28
35
29 admin_right = Right.find_by_name('user_admin')
36 admin_right = Right.find_by_name('user_admin')
30 admin_right.destroy unless admin_right==nil
37 admin_right.destroy unless admin_right==nil
You need to be logged in to leave comments. Login now