[RUBY] I want to display an error message when registering in the database


When I was writing the test code and tried to display the error message, I didn't understand it, so keep a record.

How to display error messages

In the view directory


<% if model.errors.any? %>
  <div id="error_explanation" class="alert alert-danger">
      <% model.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
<% end %>

And call it with the render method. The model on the first line is supposed to register something in the database this time.

Calling code

<%= render 'error_messages', model: f.object %>

Depending on the location of the file, you need to specify something like shared / error_messages.

Recommended Posts

I want to display an error message when registering in the database
I tried to translate the error message when executing Eclipse (Java)
I want to display the images under assets/images in the production environment
I want to control the default error message of Spring Boot
I want to send an email in Java.
What I did when JSF couldn't display database information in the view
I want to make the frame of the text box red when there is an input error
I want to get the IP address when connecting to Wi-Fi in Java
I want to get the value in Ruby
I get an error when I try to use "^" or "$" in ruby ​​regular expression
I want to embed any TraceId in the log
I want to display the name of the poster of the comment
[Rails] How to display an image in the view
[Rails] I want to display the link destination of link_to in a separate tab
Customize the display when an error such as 404 Not Found occurs in Spring Boot
I want to set the conditions to be displayed in collection_check_boxes
Display an error screen during the download process to response
I want to transition to the same screen in the saved state
I want to narrow down the display of docker ps
[Rails] How to display information stored in the database in view
I want to simplify the conditional if-else statement in Java
I want you to put the story that the error was solved when you stabbed the charger in the corner of your head
Processing to issue an error message
I want to control the display of the upper management navigation bar (Control menu) in Liferay 7 / DXP
I found no way to get the error code when I received an exception on Android
[Ruby] I want to put an array in a variable. I want to convert to an array
How to output the value when there is an array in the array
I want to remove the top margin in Grouped UITableView (swift)
[Java] I want to perform distinct with the key in the object
How to solve the unknown error when using slf4j in Java
I don't see an error in Rails bundle install ... the solution
I want to change the value of Attribute in Selenium of Ruby
[Android] I want to get the listener from the button in ListView
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
[Programming beginner] What to do when rails s becomes an error in the local development environment
I want to make an ios.android app
I want to display background-ground-image on heroku.
I want to use @Autowired in Servlet
How to display error messages in Japanese
[Ruby] I want to output only the odd-numbered characters in the character string
I want to write JSP in Emacs more easily than the default.
I summarized the points to note when using resources and resources in combination
I want to display the number of orders for today using datetime.
I tried to summarize the stumbling points when developing an Android application
I want to know the JSP of the open portlet when developing Liferay
What to do and how to install when an error occurs in DXRuby 1.4.7
How to display error messages and success messages when registering as a user
[Ruby] I want to display posted items in order of newest date
I want to display a PDF in Chinese (Korean) with thin reports
I want to ForEach an array with a Lambda expression in Java
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
It should be the same as the sample when logging in to Twitter, but an error occurs ~ resolution
I want to import the pull-down menu items when submitting a form in Rails into CSV and display them from the DB data.
Possibility when deploying to EC2 but nothing is displayed in the error log
When I renew the certificate with CircleCI × fastlane, I get an exit status: 65 error.
I want to output the day of the week
When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.
I tried to organize the session in Rails
I want to use arrow notation in Ruby
When the server fails to start in Eclipse
I get an error when adding a dependency