Home>

I am creating a new registration form
At that time, if the required item is empty or half-width,
Like'Full-width characters'
I want to display an error message

Just refresh the new registration page
Like'Full-width characters'
No error message is displayed
Corresponding source code

model.user.rb

class User</pre>
<p><br />
registrations/new.html.erb</p>
<pre><code><% = render "shared/second-header"%><% # If it is a User model, pass @user as the "model name". For "path to new registration function", execute rails routes after installing devise, check the path to devise/registrations # create, and enter it. %><% = form_with model: @user, url: user_registration_path, class:'registration-main', local: true do | f |%><% # // Pass @user to "model name" if it is a User model. For "path to new registration function", execute rails routes after installing devise, check the path to devise/registrations # create, and enter it. %>          Enter member information
      
<% render'shared/error_messages', model: f.object%>** ← Here
Read _error_messages.html.erb **

          <label>Nickname</label>  <span>Required</span>    <% = f.text_area: nickname, class: "input-default", id: "nickname", placeholder: "Example) furima Taro", maxlength: "40"%>        <label>email address</label>  <span>Required</span>    <% = f.email_field: email, class: "input-default", id: "email", placeholder: "either PC or mobile", autofocus: true%>          <label>password</label>  <span>Required</span>    <% = f.password_field: password, class: "input-default", id: "password", placeholder: "6 or more single-byte alphanumeric characters"%><p class ='info-text'>* Please set including both letters and numbers</p>          <label>Password (confirmation)</label>  <span>Required</span>    <% = f.password_field: password, class: "input-default", id: "password-confirmation", placeholder: "Enter the same password"%>    <p class ='form-info-header'>    Identification
  </p><p class ='form-info-text'>    Please cooperate in the registration of your personal information so that you can use it safely and securely. It will not be disclosed to other customers.
  </p>          <label>Name (double-byte)</label>  <span>Required</span>          <% = f.text_area: last_name, class: "input-name", id: "last-name", placeholder: "Example) Yamada"%>  <% = f.text_area: first_name, class: "input-name", id: "first-name", placeholder: "Example) Rikutaro"%>              <label>Name Kana (double-byte)</label>  <span>Required</span>          <% = f.text_area: last_name_kana, class: "input-name", id: "last-name-kana", placeholder: "Example) Yamada"%>  <% = f.text_area: first_name_kana, class: "input-name", id: "first-name-kana", placeholder: "Example) Rikutarou"%>          <label>Date of birth</label>  <span>Required</span>          <% = raw sprintf (
                  f.date_select (
                    : birthday,
                    class:'select-birth',
                    id: "birth-date",
                    use_month_numbers: true,
                    prompt:'-',
                    start_year: 1930,
                    end_year: (Time.now.year -5),
                    date_separator:'% s'),
                  "<p>Year</p>", "<p>Month</p>") + "<p>Day</p>"%>    <p class ='info-text'>* Please enter your personal information correctly. After registering as a member, it may take some time to correct it.</p>            By pressing the "Membership Registration" button
    <span>Terms of Service</span>    It is considered that you have agreed to<br>        <% = f.submit "Membership registration", class: "register-red-btn"%><p class ='register-info'>Registration of personal information</p><% end%><% = render "shared/second-footer"%>


shared/_error_messages/html.erb

<% if model.errors.any?%><ul><% model.errors.full_messages.each do | message |%><li class ='error-message'><% = message%></li><% end%></ul><% end%>
What I tried

I think the link destination of the page is different,
I moved _error_messages/html.erb to another folder, but
I got another error, so I moved it back to the first folder
I also changed the error message to Japanese,
No error message was displayed

Supplementary information (FW/tool version, etc.)
  • Answer # 1

    Resolved with<% = render'shared/error_messages', model: f.object%>