[RUBY] [Rails] Introducing devise

Introduction

devise is a gem for easy implementation of user management functions.

table of contents

  1. Install devise
  2. Create devise configuration file
  3. Creating a model
  4. Create table
  5. Edit view
  6. Edit controller

1. Install devise

Describe the following in the gemfile.

gemfile


gem 'devise'

In the app's directory, do the following:

Terminal
bundle install

** Restart the server ** after installing the gem. The gem will be reflected by restarting the server.

Terminal
rails s

2. Create a devise config file

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.

Terminal
rails g devise:install

3. Create a model

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.

Terminal
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.

4. Create table

If you want to add the required columns, write them in the migration file and execute the following.

Terminal
rails db:migrate

5. Edit view

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:

Terminal
rails g devise:views

6. Edit controller

Also, if you want to edit the controller, you can create a controller under devise management by executing the following.

Terminal
rails g devise:controllers users

Recommended Posts

[Rails] Introducing devise
Introducing devise
[Rails] devise
Introducing devise
[Rails] Introducing jquery
rails + devise + devise_token_auth
Introducing CircleCI to Rails
[Rails] devise helper method
Introducing Bootstrap to Rails 5
[Rails] Customize devise validation
Introducing Bootstrap to Rails !!
[Rails] Introducing Active Hash
Handle devise with Rails
Introducing Rails6 + Bootswatch / Honoka
[Rails] devise introduction method
[rails] About devise defaults
[Rails] Introduction of devise Basics
[Rails] After introducing (intentionally) devise, the command stopped working
What is Rails gem devise?
[Rails] gem devise installation flow
[Rails] How to install devise
Introducing Bootstrap and Font-Awesome (Rails)
(For beginners) [Rails] Install Devise
[Rails] Add column to devise
[rails] error during devise installation
Memorandum [Rails] User authentication Devise
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] Session timeout setting in devise
[rails] Login screen implementation in devise
[Devise] rails memo basic setting initial setting
Introducing full calendar to Rails application
[Rails] Unexpected validation error in devise
[Rails] [Devise] Edit profile without password
Ruby On Rails devise routing conflict
[Rails] Add strong parameters to devise
Create My Page with Rails devise
Introducing React to Rails with react-rails
[Rails] Manage multiple models using devise gem
[Rails g.error]
Rails basics
Rails Review 1
Rails API
Rails migration
Introducing RSpec
rails tutorial
About Rails 6
Rails foundation
Rails g devise: install cannot be executed!
Rails memorandum
rails tutorial
rails tutorial
rails tutorial
[Rails 6] Introducing Google Maps to your portfolio
About devise
Devise procedure
[Note] How to use Rails 6 Devise + cancancan
rails tutorial
rails tutorial
The process of introducing Vuetify to Rails
Rails Tips