devise is a gem for easy implementation of user management functions.
Describe the following in the gemfile.
gemfile
gem 'devise'
In the app's directory, do the following:
bundle install
** Restart the server ** after installing the gem. The gem will be reflected by restarting the server.
rails s
In order to use devise, in addition to installing the gem, it is necessary to create a configuration file with a command dedicated to devise. By executing the following, you can automatically generate the "file used for setting" of the added devise gem.
rails g devise:install
When using devise, it is necessary to create a new User model for creating an account. To create it, create a User model with devise's model creation command instead of the usual model creation method.
rails g devise user
In addition to automatically generating models and migrations with the rails g devise command, routes are also automatically added to routes.rb.
If you want to add the required columns, write them in the migration file and execute the following.
rails db:migrate
If you add a column, you need to edit the view of the new registration screen so that you can enter the added column. By default, devise's view files are hidden, so do the following:
rails g devise:views
Also, if you want to edit the controller, you can create a controller under devise management by executing the following.
rails g devise:controllers users
Recommended Posts