<%= render '〇〇/error_messages', model: f.object %>
2.〇〇/_error_messages.html.erb Create and describe a file.
#〇〇/_error_messages.html.Contents of erb
<%if variable A.errors.any? %>
<div id="error_explanation">
<ul>
<%Variable A.errors.full_messages.each do |message| %>
<li class="error-alert"><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
def create
@item= Item.new(item_params)
if @item.save
redirect_to action: 'index'
else
render :new
end
end
Recommended Posts