Today's learning summary: With user management function implementation

Introduction

This time, I'm writing a lot of things that I want to remember completely for myself.

Regular expressions


PASSWORD_REGEX = /\A(?=.*?[A-z])(?=.*?[\d])[A-z\d]+\z/i.freeze #One or more half-width alphanumeric characters
ZENKAKU_REGEX = /\A[Ah-Hmm-One-龥]+\z/.freeze #Full-width Hirakata Kanji
KANA_REGEX = /\A[A-Car-]+\z/.freeze #full-width Kana

freeze is to keep variables unchanged.

Summarize validation options


with_options presence: true do
 validates #Add options
end

Display an error message

Call the file with the render method in foem_with. At that time, describe as if it is a file under devise.


<%= form_with model: @user, url: user_registration_path', local: true do |f| %>
  <%= render 'devise/shared/error_messages', model: f.object %>

ruby:_error_messages.html.erb


<% if model.errors.any? %>
  <div id="error_explanation">
    <h2>
      <%= I18n.t("errors.messages.not_saved",
                 count: model.errors.count,
                 resource: model.class.model_name.human.downcase)
       %>
    </h2>
    <ul>
      <%= model.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
    </ul>
  </div>
<% end %>

Write to call model.


Recommended Posts

Today's learning summary: With user management function implementation
Login function implementation with rails
[Rails] Implementation of user withdrawal function
Implementation of user authentication function using devise (2)
Implementation of user authentication function using devise (1)
I tried time-saving management learning with Studyplus.
Implementation of user authentication function using devise (3)
Implementation of search function Learning memo (portfolio creation)
Android application implementation TIPS, reference site summary (function implementation)
DM function implementation
[Rails] Implementation of drag and drop function (with effect)