title: Displaying products by category in Rails
body: <p>Rails beginner here.  I want to display a list of all products belonging to a specific category.  I wanted to keep it simple, so each product has only one category. When I show the category, the products are there, but they appear in an array, like this:</p>
  
  <blockquote>
    <blockquote>
      <p>Name: Soldering</p>
      
      <p>Category ID: 2</p>
      
      <p>Products: [#&lt; Product id: 5, title: "Hacksaw", description: "Finetooth Hacksaw", image_url: >>"hacksaw.jpg", price: #, created_at: "2012-07-14 >>22:34:07", updated_at: "2012-07-17 22:18:14", category_id: 2, category_name: nil>, #&lt; Product id:8, >>title: "Torch", description: "Welding Torch", image_url: "torch.jpg", price: >>#, created_at: "2012-07-15 08:40:05", >>updated_at: "2012-07-15 08:40:05", category_id: 2, category_name: nil>]</p>
    </blockquote>
  </blockquote>
  
  <p>This is the categories/show.html.erb:</p>
  
  <pre><code>&lt;p&gt;
    &lt;b&gt;Products:&lt;/b&gt;
    &lt;%= @category.products %&gt;&lt;/p&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>And the categories controller:</p>
  
  <pre><code>def show
    @category = Category.find(params[:id])
  
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @category }
    end
  end
  </code></pre>
  
  <p>What I want to do is just display a list of the products names, but when I try this in the show.html.erb:</p>
  
  <pre><code>&lt;p&gt;
      &lt;b&gt;Products:&lt;/b&gt;
      &lt;%= @category.product.name %&gt;&lt;/p&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>...I get the following error:</p>
  
  <blockquote>
    <blockquote>
      <p>undefined method `product' for #&lt; Category:0x007ff03cd59e98></p>
    </blockquote>
  </blockquote>
  
  <p>I can't figure out what's wrong.</p>