[RUBY] Summary about the introduction of Device

* The notes are filled in from application creation to Devise installation.

Premise

ruby 6.0.0 rails 6.0.3.4 mysql2 0.5.3 devise 4.7.3

Create in the above environment.

Simple flow

① Launch the application you want to create.

console


% rails _6.0.0_new app name-d mysql

(2) Rewrite the description of database.yml in the app.

config/database.yml


#Omission
default: &default
  adapter: mysql2
#↓ ↓ Originally encoding: utf8mb4
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

#The following is omitted

③ Enter the gem you want to add to the bottom layer in the gemfile.

Gemfile


#Omission
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'pry-rails'
gem 'devise'

④ Load the gem.

console


% bundle install

console


% yarn install

⑤ Create a database in the directory of the created application on the console.

console


% rails db:create

⑥ Install Devise on the app.

console


% rails g devise:install

(7) Generate a model using Devise. (Migration files and routing are also automatically generated.)

console


#Model name is singular
%rails g devise model name

⑧ Create a view file for new registration and login.

console


% rails g devise:views

⑨ Start the local server.

console


% rails s

⑩ Describe the column to be added to the migration file.

  1. Migrate the table.

console


% rails db:migrate
  1. Make each edit / setting. view/devise/registrations → Edit new registration screen view/devise/sessions → Edit login screen model/table name.rb → Validation settings

  2. Edit application_controller.rb.

controllers/application_controller.rb


class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  private
  def configure_permitted_parameters
#The content of keys is the column name added to the devise table
    devise_parameter_sanitizer.permit(:sign_up, keys: [:Column 1, :Column 2, ‥])
  end
end

that's all

Other notes etc.

-The routing to reach the new registration page and login page is automatically generated when the model is created.

-Since the controller processing required for the user management function is hidden behind the scenes, it will be described in "application_controller.rb" that controls the controller.

・ If "rails g devise: install" doesn't work, try the following.

console


$ bundle exec spring stop

Recommended Posts

Summary about the introduction of Device
About the handling of Null
About the description of Docker-compose.yml
Talking about the merits of database bind variables ((1) Introduction)
About the behavior of ruby Hash # ==
About the role of the initialize method
Think about the 7 rules of Optional
About the log level of java.util.logging.Logger
About the version of Docker's Node.js image
About the operation of next () and nextLine ()
About the initial display of Spring Framework
About the error message Invalid redeclaration of'***'
Output of the book "Introduction to Java"
About the treatment of BigDecimal (with reflection)
About the number of threads of Completable Future
About the mechanism of the Web and HTTP
Introduction of pay.jp
Introduction of milkode
About MacinCloud introduction
About the package
[Ruby] Summary of class definitions. Master the basics.
Think about the combination of Servlet and Ajax
Summary of what I learned about Spring Boot
About the official start guide of Spring Framework
About the description order of Java system properties
[Docker] Introduction to docker compose Basic summary of docker-compose.yml
[Ruby on Rails] Until the introduction of RSpec
About the idea of anonymous classes in Java
About next () and nextLine () of the Scanner class
[Note] About the introduction to Swift practice Chapter 11
Output about the method # 2
From the introduction of devise to the creation of the users table
About the StringBuilder class
The world of clara-rules (2)
Commentary: About the interface
About disconnect () of HttpURLConnection
Introduction of Docker --Part 1--
About the asset pipeline
About the function double-java
[Grails] About the setting area and the setting items of application.yml
About the usefulness of monads from an object-oriented perspective
[Rails] Introduction of PAY.JP
About selection of OpenJDK
Summary of OpenJDK sources
About DI of Spring ①
Summary of strong parameters
About the ternary operator
Judgment of the calendar
The world of clara-rules (4)
Summary of jar files
The world of clara-rules (1)
About DI of Spring ②
The world of clara-rules (3)
About the length method
Summary of information security
Summary of using FragmentArgs
About the Kernel module
The world of clara-rules (5)
The idea of quicksort
About the authenticate method.
Personal summary about Java