[RUBY] No error message is displayed when create action fails

Background of the problem

The background is as the title. I was able to save it without any problems, but when the save failed, no error message was displayed and I was having a hard time. (Partial code excerpt)

laundries_controller.rb


def create
  @laundry = Laundry.new(laundry_params)
  if @laundry.save
    redirect_to root_path
  else
      render :new
  end
end

ruby:new.html.erb


<%= form_with model:@laundry, url: laundries_path, locals: true do |f| %>
  <%= render 'error_messages', model: f.object %>

Conclusion

There was an error in the description of the view file. Positive

local: true

Wrong

locals: true

The error statement was displayed safely by correcting the description to the correct one. The error message was not displayed correctly because the communication was asynchronous due to a description error. By the way, `locals``` can define variables used in partial templates with the option of `render``` method. It's only one letter difference, but the difference changes the behavior, so I realized that I had to be careful.

Digression

I want to display the code when creating an article, but it does not go well and I have a hard time ... When displaying the code, you have to leave blank lines before and after the backticks. I felt it was important to remember while actually moving my hands.

Recommended Posts

No error message is displayed when create action fails
When submitting form, no error message is displayed even though validation failed
The devise error message is not displayed properly.
[No Method Error] Solution when new action occurs
rails [Procedure for displaying an error statement when data transmission fails due to create action]
timestamp status 999 error none message no message available
When UITextView is not displayed (Swift, Xcode)
Possibility when deploying to EC2 but nothing is displayed in the error log
[Heroku] How to solve when an error is displayed on git push heroku master
Error handling when Gradle dependency is using SLF4J
Rails <% = expression%> Why no error occurs when empty
When the project is not displayed in eclipse
No Xcode or CLT version detected! Is displayed when npm install is performed with Laravel