Skip to content

Commit bb8580a

Browse files
committed
User モデルにバリデーションを追加
1 parent 460303d commit bb8580a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

depot/app/models/user.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1+
# -*- coding: utf-8 -*-
12
class User < ActiveRecord::Base
3+
4+
validates_presence_of :name
5+
validates_uniqueness_of :name
6+
7+
attr_accessor :password_confirmation
8+
validates_confirmation_of :password
9+
10+
validate :password_non_blank
11+
12+
private
13+
14+
def password_non_blank
15+
errors.add(:password, "パスワードを入れてください") if hashed_password.blank?
16+
end
217
end

0 commit comments

Comments
 (0)