[RUBY] [Rails] Introduction of devise Basics

A gem for user management in Rails apps, The basic procedure for introducing "devise" Introduced as a memorandum.

1. Add devise to Gemfile

Described in the bottom line.

Gemfile


gem 'devise'

Run ** bundle instrall **.

2. Apply devise

Terminal


rails g devise:install

3. Create a user model with devise specifications

Unlike the normal model creation command, it is a devise-specific command, Create a User model.

Terminal


rails g devise user

After execution, "devise_for: users" is added to the routing, It seems that login and new registration will generate the required routing.

◉ Continue to execute.

Terminal


rails db:migrate

4. Allow new registration / login

Create a button for "new registration" and "login" in the header etc. Due to the ** user_signed_in? Method **, the display will be different when you are not logged in than when you are logged in.

sample.haml


.header
  .header__user-btn
    - if user_signed_in?
      = link_to "New post", new_post_path, class: "btn"
      = link_to "Log out", destroy_user_session_path, method: :delete, class: "btn"
    - else
      = link_to "Login", new_user_session_path, class: "btn"
      = link_to "sign up", new_user_registration_path, class: "btn"

Create a view for devise

Display the screen for actually entering registration and login information.

rails g devise:views

Up to this point, registration → login → logout has been implemented.


That is all. Thank you for visiting.

Recommended Posts

[Rails] Introduction of devise Basics
[Rails] Introduction of PAY.JP
[Rails] devise introduction method
Rails basics
[Rails] devise
[Rails] Introduction of Rubocop by beginners
Rails CSV basics
[Ruby on Rails] Introduction of initial data
Rails Routing Basics
Rails database basics
Introduction of pay.jp
Rails Logger Basics
Introduction of milkode
[Rails 6] cocoon_ introduction
Basics of Ruby
[Rails] Introducing devise
rails + devise + devise_token_auth
Rails Basics of creating a new application
Rspec Basics [Rails]
[Vue.js] Implementation of menu function Vue.js introduction rails6
[Rails] Introduction of pry-rails ~ How to debug binding.pry
[Ruby on Rails] Until the introduction of RSpec
Rails: Japanese localization of validation messages including devise
Ruby on Rails ~ Basics of MVC and Router ~
[Note] Summary of rails login function using devise ①
[Introduction to Java] Basics of java arithmetic (for beginners)
Introduction of Docker --Part 1--
[Rails] devise helper method
[Rails] Customize devise validation
Handle devise with Rails
Rails Tutorial/Significance of Indexing
Ruby on Rails basics
Basics of try-with-resources statement
Introduction of user authentication
[rails] About devise defaults
From the introduction of devise to the creation of the users table
Implementation of Ruby on Rails login function (devise edition)
Japaneseization of Rails error messages [devise / Form objects, etc.]
[Rails] Cancel / change the default password validation of devise
[Rails] Initial setting of user-created login with devise, devise_token_auth
Rails implementation of ajax removal
I made a Japanese version of Rails / devise automatic email
Docker monitoring-explaining the basics of basics-
[Rails] Register by attribute of the same model using Devise
What is Rails gem devise?
[GCD] Basics of DispatchQueue class
Basics of character operation (java)
[Rails] gem devise installation flow
[Rails] How to install devise
[Docker] Introduction of basic Docker Instruction
Basics such as devise pagination
Utilization of Rails Boolean type
Understand the basics of docker
I was addicted to setting default_url_options with Rails devise introduction
[Rails 6] Implementation of search function
[Japanese localization of gem: devise]
[Rails] Implementation of category function
The basics of Swift's TableView
(For beginners) [Rails] Install Devise
[Rails] Add column to devise
[Rails] When the layout change of devise is not reflected