我正在创建一个非常基本的Rails应用程序(学习教程),无法理解为什么会出现此错误。
我尝试过故障排除,但无济于事。
<div id="page_wrapper">
<h1> Make Something </h1>
<%= form_for :post, url: posts_path do |f| %>
<% if @post.errors.any? %>
<div id="errors">
<h2> <%= pluralize(@post.errors.count, "error" %> stopped this post from saving </h2>
<ul>
<% @post.errors.full_message.each do |msg| %>
<li> <%= msg %> </li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %> <br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %> <br>
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</div>
我希望得到更好的UI错误消息,但不知道我的错误是什么-我确信这是一个非常小的语法修复程序,但您的帮助将不胜感激。
调用复数时您没有关闭方括号
更改
<h2> <%= pluralize(@post.errors.count, "error" %> stopped this post from saving </h2>
to
<h2> <%= pluralize(@post.errors.count, "error") %> stopped this post from saving </h2>