Skip to content

Commit 60a19c1

Browse files
committed
optimize validation
1 parent 986427d commit 60a19c1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/models/user.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ class User < ActiveRecord::Base
170170
validates :username,
171171
exclusion: {in: RESERVED, message: "is reserved"},
172172
format: {with: VALID_USERNAME, message: "must not contain a period"},
173-
presence: true,
174-
uniqueness: true
173+
uniqueness: true,
174+
if: :username_changed?
175175

176+
validates_presence_of :username
176177
validates_presence_of :email
177178
validates_presence_of :location
178179
validates :email, email: true, if: :not_active?

0 commit comments

Comments
 (0)