Skip to content

Commit c607472

Browse files
committed
add validation in User
1 parent 9edb160 commit c607472

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/models/user.rb

+12
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
class User < ActiveRecord::Base
2+
validates :name, :presence => true, :uniqueness => true
3+
4+
validates :password, :confirmation => true
5+
attr_accessor :password_confirmation
6+
attr_reader :password
7+
8+
validate :password_must_be_present
9+
10+
private
11+
def password_must_be_present
12+
errors.add(:password, "Missing password") unless hashed_password.present?
13+
end
214
end

db/schema.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended to check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(:version => 20110403043457) do
13+
ActiveRecord::Schema.define(:version => 20110403122207) do
1414

1515
create_table "carts", :force => true do |t|
1616
t.datetime "created_at"
@@ -44,4 +44,12 @@
4444
t.datetime "updated_at"
4545
end
4646

47+
create_table "users", :force => true do |t|
48+
t.string "name"
49+
t.string "hashed_password"
50+
t.string "salt"
51+
t.datetime "created_at"
52+
t.datetime "updated_at"
53+
end
54+
4755
end

0 commit comments

Comments
 (0)