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 %>
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.
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