Devise procedure

Root path setting

routes.rb


root to: "home#index"

Add Gem

Gemfile


gem 'devise'
$ bundle

Generate devise config file

$ rails g devise:install

Creating a user model

$ rails g devise user

Added to migration file

t.string :name 
$ rails db:migrate

Create view

$ rails g devise:views

Add the following code to register the user name at the time of new registration

application_controller.rb


before_action :configure_permitted_parameters, if: :devise_controller?

protected
def configure_permitted_parameters
  devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end

Add flash message

ruby:application.html.erb


<%= render 'layouts/flash_messages' %>

ruby:_flash_messages.html.erb (For bulma)


<% if flash[:notice] %>
  <div class="notification is-info">
    <p class="notice"><%= notice %></p>
  </div>
<% end %>
<% if flash[:alert] %>
  <div class="notification is-danger">
    <p class="alert"><%= alert %></p>
  </div>
<% end %>

application.scss (change to scss for css)


.notification:not(:last-child){
  margin-bottom: 0;
}

Add user column to new registration View

ruby:registrations/new.html.erb


<div class="field">
  <%= f.label :name %><br />
  <%= f.text_field :name, autofocus: true, autocomplete: "name" %>
</div>

Recommended Posts

Devise procedure
About devise
[Rails] devise
Introducing devise
devise user registration
eclipse installation procedure
[Rails] Introducing devise
JavaCC setup procedure
rails + devise + devise_token_auth