title: Show association errors in a form
body: <p>I have a model: review.rb</p>
  
  <pre><code>class Review &lt; ActiveRecord::Base
    validates :title, :presence =&gt; true
    belongs_to :product
  end
  </code></pre>
  
  <p>model: product.rb</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    validates :name, :presence =&gt; true
  
    has_many :reviews, :dependent =&gt; :destroy
  end
  </code></pre>
  
  <p>and this form: _form.html.haml</p>
  
  <pre><code>=form_for([@product, @product.reviews.build]) do |f|
    .field
      =f.label :title
      %br
      =f.text_field :title
  </code></pre>
  
  <p>with this reviews_controller:</p>
  
  <pre><code>def create
    @product = Product.find(params[:product_id])
    @review = @product.reviews.create(params[:review])
    redirect_to product_path(@product)
  end
  </code></pre>
  
  <p>When I add a review with no title the review doesn't get created because the title is required (which is good). I'm not sure how to get the errors to show on this association though.</p>
  
  <p>I tried this:</p>
  
  <pre><code>=form_for([@product, @product.reviews.build]) do |f|
    -if @product.reviews.errors.any?
      .errors
        %h2
          =pluralize(@product.reviews.errors.count, "error")
        %ul
          =@product.reviews.errors.full_messages.each do |msg|
            %li
              =msg
  </code></pre>
  
  <p>but got this error:</p>
  
  <pre><code>undefined method `errors' for #&lt;ActiveRecord::Relation:0x00000103e31df0&gt;
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>  -if @review.errors.any?
      .errors
        %h2
          =pluralize(@review.errors.count, "error")
        %ul
          =@review.errors.full_messages.each do |msg|
            %li
              =msg
  </code></pre>
  
  <p>And got:</p>
  
  <pre><code>undefined method `errors' for nil:NilClass
  </code></pre>
  
  <p>In the controller when I:</p>
  
  <pre><code>    raise @review.errors.inspect
  </code></pre>
  
  <p>I can see the errors:</p>
  
  <pre><code>#&lt;ActiveModel::Errors:0x00000103d88c28 @base=#&lt;Review id: nil, title: "", description: "", rating: nil, helpful: nil, product_id: 1, created_at: nil, updated_at: nil&gt;, @messages={:title=&gt;["can't be blank", "is too short (minimum is 5 characters)"]}&gt;
  </code></pre>
  
  <p>What am I forgetting? How do I get the errors to show?</p>
  
  <p>Thank you</p>