Adding Users
Learn how to add new users to the existing app
We'll cover the following...
Let’s start by creating a model and database table to hold our administrators’ usernames and passwords. Rather than store passwords in plain text, we’ll store a digest hash value of the password. By doing so, we ensure that even if our database is compromised, the hash won’t reveal the original password. We will use the forms:
depot> bin/rails generate scaffold User name:string password:digest
We declare the password as a digest
type, which is another one of the nice
extra touches that Rails provide. Now run the migration as usual:
depot> bin/rails db:migrate
A live terminal
You can run the above commands by using the following terminal.
Next, we have to flesh out the user model:
Press + to interact
class User < ApplicationRecordvalidates :name, presence: true, uniqueness: truehas_secure_passwordend
We check that the name is present and unique, meaning that no two users can have the ...