Description:
add_email_to_user, fix empty problem for_in_place_editing git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@42 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

r18:d8813c40713d - - 5 files changed: 42 inserted, 4 deleted

@@ -0,0 +1,9
1 + class AddEmailToUsers < ActiveRecord::Migration
2 + def self.up
3 + add_column :users, :email, :string
4 + end
5 +
6 + def self.down
7 + remove_column :users, :email
8 + end
9 + end
@@ -3,13 +3,14
3 3 before_filter :authenticate
4 4
5 5 verify :method => :post, :only => [:chg_passwd],
6 6 :redirect_to => { :action => :index }
7 7
8 8 in_place_edit_for :user, :full_name
9 - in_place_edit_for :user, :alias
9 + in_place_edit_for :user, :alias_for_editing
10 + in_place_edit_for :user, :email_for_editing
10 11
11 12 def index
12 13 @user = User.find(session[:user_id])
13 14 end
14 15
15 16 def chg_passwd
@@ -25,13 +25,37
25 25 end
26 26
27 27 def admin?
28 28 self.roles.detect {|r| r.name == 'admin' }
29 29 end
30 30
31 - # protected
31 + def email_for_editing
32 + if self.email!=nil
33 + self.email
34 + else
35 + "unknown"
36 + end
37 + end
38 +
39 + def email_for_editing=(e)
40 + self.email=e
41 + end
42 +
43 + def alias_for_editing
44 + if self.alias!=nil
45 + self.alias
46 + else
47 + "unknown"
48 + end
49 + end
50 +
51 + def alias_for_editing=(e)
52 + self.alias=e
53 + end
54 +
55 + protected
32 56 def encrypt_new_password
33 57 return if password.blank?
34 58 self.salt = (10+rand(90)).to_s
35 59 self.hashed_password = encrypt(password,salt)
36 60 end
37 61
@@ -11,13 +11,16
11 11 %td.uinfo= @user.login
12 12 %tr
13 13 %th.uinfo Full name
14 14 %td.uinfo= in_place_editor_field :user, 'full_name', {}, :rows => 1
15 15 %tr
16 16 %th.uinfo Alias
17 - %td.uinfo= in_place_editor_field :user, 'alias', {}, :rows => 1
17 + %td.uinfo= in_place_editor_field :user, 'alias_for_editing', {}, :rows => 1
18 + %tr
19 + %th.uinfo E-mail
20 + %td.uinfo= in_place_editor_field :user, 'email_for_editing', {}, :rows => 1
18 21 %tr
19 22 %th.uinfo Password
20 23 %td.uinfo
21 24 - form_tag :action => 'chg_passwd', :method => 'post' do
22 25 %table
23 26 %tr
@@ -6,13 +6,13
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 11) do
12 + ActiveRecord::Schema.define(:version => 12) do
13 13
14 14 create_table "languages", :force => true do |t|
15 15 t.string "name", :limit => 10
16 16 t.string "pretty_name"
17 17 t.string "ext", :limit => 10
18 18 end
@@ -82,11 +82,12
82 82 create_table "users", :force => true do |t|
83 83 t.string "login", :limit => 10
84 84 t.string "full_name"
85 85 t.string "hashed_password"
86 86 t.string "salt", :limit => 5
87 87 t.string "alias"
88 + t.string "email"
88 89 end
89 90
90 91 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
91 92
92 93 end
You need to be logged in to leave comments. Login now