Add gem'devise' in Gemfile
bundle install in the terminal
Here, it will not be reflected unless the server is started with rails s
Create a configuration file with rails g devise: install
The point to note here is that it is not the same as when making a normal model.
--Enter rails g devise user in the terminal (at this time, routing is automatically set and migration file is also generated)
class DeviseCreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| t.string :name, null: false t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: ""
--Create a table with the rails db: migrate command in the terminal
The information you enter when signing up is sent to the server as a parameter. Normally, the strong parameters of the controller limit the parameters received, but when devise, the writing method is different.
Parameters can be obtained from requests such as "login" and "new registration" related to devise's User model. The description below allows a key parameter called a nickname when signing up. In fact, the items required for new registration will be added after the nickname. Note that the arguments in permit here are different from normal parameters!
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? private def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) end end
The first before_action is the setting to execute the configure_permitted_paramaters method if it is a process by devise. You need a whole thing, but you don't have to remember it all because it will come out when you look up this area.
As a result, the information at the time of new registration can be saved in the table.