title: Rails model to_s method
body: <p>In my Rails application there is a relationship defined between Products and Categories. Each product can have different categories.</p>
  
  <p>I am displaying the product's category this way:</p>
  
  <pre><code>&lt;p&gt;
      &lt;strong&gt;Categories:&lt;/strong&gt;
      &lt;%= @product.categories.join(", ") unless @product.categories.nil? %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>And my <code>Category</code> model:</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
      def to_s
          @name
      end
  end
  </code></pre>
  
  <p>However, in the show page, the categories are displayed like this:</p>
  
  <pre><code>Categories: #&lt;Category:0x007f2bf515b148&gt;, #&lt;Category:0x007f2bf515aef0&gt;, #&lt;Category:0x007f2bf515ac98&gt;
  </code></pre>
  
  <p>Why is the <code>to_s</code> method not working? How can I solve this?</p>