title: How do I access database information from a Rails view?
body: <p>When I try to look at my index.html.erb file I get the following error:</p>
  
  <pre><code>NoMethodError in Products#index
  undefined method `name' for #&lt;Product:0x4a77de8&gt;
  </code></pre>
  
  <p>Here is my code</p>
  
  <p>Controller:</p>
  
  <pre><code>class ProductsController &lt; ApplicationController
    .
    .
    .
  
    def index
      @products = Product.all
    end
  end
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;h1&gt;List of products&lt;/h1&gt;
  
  &lt;table&gt;
  &lt;% @products.each do |product| %&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;%= product.name %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;%= product.description %&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;%= product.price %&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I thought the controller would gather all the entries I have inputted into the 'Product' table in the database and place them into the @products variable. After that I thought the view should iterate through the items in @products and call the name, description, price values for each product and output a table.</p>
  
  <p>Where have I gone wrong here?</p>
  
  <p>Any help appreciated thanks alot.</p>