0

I am making a rails app that users can use to shop for products. Everything was working fine, then I adjusted the products#index page, and now the data from the database is displaying on the html under the <div> of the page like so;

[#&lt;Product id: 1, name: &quot;Green&quot;, description: &quot;coming from the hills of the emerald triangle, thi...&quot;, strain: &quot;Sativa&quot;, price: #&lt;BigDecimal:7fbe558f8228,&#39;0.2E2&#39;,9(18)&gt;, image_file_name: &quot;http://i.imgur.com/NZkyXpr.jpg&quot;, created_at: &quot;2015-04-12 22:56:42&quot;, updated_at: &quot;2015-04-12 22:56:42&quot;, gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil&gt;, #&lt;Product id: 3, name: &quot;Sour Diesel&quot;, description: &quot;Sour, sometimes called Sour D, is an invigo...&quot;, strain: &quot;Hybrid&quot;, price: #&lt;BigDecimal:7fbe55902bd8,&#39;0.2E2&#39;,9(18)&gt;, image_file_name: &quot;http://i.imgur.com/RUHZAXQ.jpg&quot;, created_at: &quot;2015-04-13 01:42:35&quot;, updated_at: &quot;2015-04-13 01:42:35&quot;, gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil&gt;, #&lt;Product id: 2, name: &quot;Grand Daddy Purp&quot;, description: &quot;Introduced in 2003 by Ken Estes, Granddaddy Purple...&quot;, strain: &quot;Indica&quot;, price: #&lt;BigDecimal:7fbe559015d0,&#39;0.2E2&#39;,9(18)&gt;, image_file_name: &quot;http://i.imgur.com/8O5kXeL.jpg&quot;, created_at: &quot;2015-04-13 01:41:17&quot;, updated_at: &quot;2015-04-13 07:31:14&quot;, gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil&gt;]

Here is my index page, along with my controller

index.html.erb

<section class="product-page">
  <div class="container">
    <div class="row text-center">
      <%= @products.each do |product| %>
        <div class="product col-md-4 text-center">
          <h2><%= link_to product.name, product_path(product.id) %></h2>
          <%= link_to image_tag(product.image_file_name),
              product_path(product.id), :class => 'img-responsive' %>
           <div class="product-info">
             <div class="product-info-left"><%= product.descrip %></div>
             <div class="product-info-right"><%= product.price %></div>
           </div>   
        </div>
        <% end %>
    </div>
  </div>
</section> 

products_controller.rb

class ProductsController < ApplicationController


  def index
    @products = Product.all
  end

  def show
    @product = Product.find(params[:id])
  end


end

Does anyone know why the data from the database would be displaying on my html page? Did I forget to close a tag, is there something in my controller? I can also attach an image that shows what it looks like if my description isn't clear. Any tips would be much appreciated.

1 Answer 1

1
<%= @products.each do |product| %>

must be

<% @products.each do |product| %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.