0
因此,舉例來說,從http://guides.rubyonrails.org/getting_started.html情況下,正如你所看到的,如果你嘗試創建無效後,你會看到錯誤消息:Rails的:一種觀點認爲,模型及其相關的模型
<%= form_for @post do |f| %>
<% if @post.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
如何實現爲關聯的評論模型渲染錯誤消息,請記住,評論創建表單位於posts/show視圖中?
謝謝,用'渲染「文章/顯示」'在評論#中創建它現在解決了我的問題。 –