This time, I will write about how to implement the user authentication function using devise.
·user registration ・ Login ・ Log out
This is an essential function for Web services. Let's go fast.
First at the bottom of the Gemfile in the rails application directory
Gemfile
gem 'devise'
It is described as. Then at the terminal
% bundle install
to hold. Since it is necessary to restart the server after bundle install
% rails s
to hold.
Then to install the devise config file into the rails application
% rails g devise:install
to hold. This command will automatically generate the files used for devise settings.
Next, create a model that manages users. The command is different from the normal model creation procedure.
% rails g devise user
Let's execute. This will generate the model and migration files for devise.
Next, let's add the necessary columns to the generated migration file.
Once you have filled in the required columns, at the terminal
% rails db:create
Create a database with
% rails db:migrate
Let's migrate with.
This completes the creation of the User model for the time being.
Recommended Posts