Skip to content

Commit

Permalink
make sure users can't have same username
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 6, 2023
1 parent 13c809f commit ed1ac79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

validates :username, uniqueness: { case_sensitive: false }

has_many :links
has_one_attached :background_image

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230906011510_add_unique_index_to_username.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUniqueIndexToUsername < ActiveRecord::Migration[7.0]
def change
add_index :users, :username, unique: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed1ac79

Please sign in to comment.