title: Show name instead of ID in has_many view table
body: <p>I have tried a couple other similar posts but am still getting an error.  </p>
  
  <p>In the Posts model I have a category_id field.  I have the following models:</p>
  
  <pre><code>#Posts model
  belongs_to :categories  
  
  #Category model
  has_many :posts
  </code></pre>
  
  <p>In the Posts index controller I have:</p>
  
  <pre><code>@categories = @posts.Category.find(:all, :order =&gt; 'categoryname')
  </code></pre>
  
  <p>In the View I have:</p>
  
  <pre><code>&lt;% @posts.each do |post| %&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;%= post.category_id %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @categories.categoryname %&gt;&lt;/td&gt;
  
  &lt;td&gt;&lt;%= link_to 'View', post %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= link_to 'Edit', edit_post_path(post) %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In the 2nd column I am trying to show the category name ("categoryname") from the Category table instead of the category_id from the posts table.  I am getting an error:  </p>
  
  <p>undefined method `Category' for #ActiveRecord::Relation:0x3e1a9b0></p>
  
  <p>I have also tried:</p>
  
  <pre><code>&lt;td&gt;&lt;%= post.categories.categoryname %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>But get the same error. </p>
  
  <p>As well as:</p>
  
  <pre><code>&lt;td&gt;&lt;%= post.category.categoryname %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Any suggestions would be greatly appreciated.  </p>