Note that there are some explanatory texts on larger screens.

plurals
  1. POf.error_messages in Rails 3.0
    text
    copied!<p>Rails 3.0 deprecated <code>f.error_messages</code> and now requires a plugin to work correctly - I however want to learn how to display error messages the (new) native way. I am following the <a href="http://edgeguides.rubyonrails.org/getting_started.html" rel="noreferrer">getting started guide</a>, which uses the deprecated method when implementing the comments form. For example:</p> <pre><code>&lt;h2&gt;Add a comment:&lt;/h2&gt; &lt;%= form_for([@post, @post.comments.build]) do |f| %&gt; &lt;%= f.error_messages %&gt; &lt;div class="field"&gt; &lt;% f.label :commenter %&gt;&lt;br /&gt; &lt;%= f.text_field :commenter %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :body %&gt;&lt;br /&gt; &lt;%= f.text_area :body %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Here is the correct way to do it (as generated by the scaffold):</p> <pre><code>&lt;%= form_for(@post) do |f| %&gt; &lt;% if @post.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@post.errors.count, "error") %&gt; prohibited this post from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @post.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; . . . </code></pre> <p>I understand that I use the <code>@post</code> variable in the latter example, but what variable do I reference in the former to get the error messages for comment creation?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload