0
votes

Product Load (4.8ms) SELECT "products".* FROM "products" => #http://www.heritagedaily.com/wp-content/uploads/20...", created_at: "2017-03-07 19:17:57", updated_at: "2017-03-07 19:17:57", colour: "brown", price: #>,

"http://www.heritagedaily.com/wp-content/uploads/20...", created_at: "2017-03-07 19:17:57", updated_at: "2017-03-07 19:17:57", colour: "brown", price: #>,

"http://www.heritagedaily.com/wp-content/uploads/20...", created_at: "2017-03-07 19:17:57", updated_at: "2017-03-07 19:17:57", colour: "brown", price: #>

And this is what i get on my localhost once i go to the product page =>

ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by StaticPagesController#landing_page as HTML Rendering static_pages/landing_page.html.erb within layouts/application DEPRECATION WARNING: uniq is deprecated and will be removed from Rails 5.1 (use distinct instead) (called from _app_views_static_pages_landing_page_html_erb__3481566516998456644_70117399973400 at /Users/jovanka/Desktop/the_antique/app/views/static_pages/landing_page.html.erb:23) Product Load (0.2ms) SELECT DISTINCT "products".* FROM "products"
Product Load (0.8ms) SELECT "products".* FROM "products" ORDER BY "products"."id" ASC LIMIT ? [["LIMIT", 1]] Rendered static_pages/landing_page.html.erb within layouts/application (20.5ms) Completed 200 OK in 428ms (Views: 404.1ms | ActiveRecord: 1.6ms)

Started GET "/cable" for ::1 at 2017-03-07 14:23:33 -0600 Started GET "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:33 -0600 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) An unauthorized connection attempt was rejected Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:33 -0600 Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:33 -0600 Started GET "/cable" for ::1 at 2017-03-07 14:23:42 -0600 Started GET "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:42 -0600 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) An unauthorized connection attempt was rejected Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:42 -0600 Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:42 -0600 Started GET "/products" for ::1 at 2017-03-07 14:23:43 -0600 Processing by ProductsController#index as HTML Rendering products/index.html.erb within layouts/application Product Load (0.2ms) SELECT "products".* FROM "products" Product: Ancient Jewellery Product: Ancient Jewellery Product: Ancient Jewellery
Rendered products/_product.html.erb (7.9ms) Product: Ancient Jewellery Product: Ancient Jewellery Product: Ancient Jewellery Rendered products/_product.html.erb (2.2ms) Product: Ancient Jewellery Product: Ancient Jewellery Product: Ancient Jewellery Rendered products/_product.html.erb (1.5ms) Rendered products/index.html.erb within layouts/application (20.9ms) Completed 200 OK in 192ms (Views: 142.1ms | ActiveRecord: 1.1ms)

Started GET "/cable" for ::1 at 2017-03-07 14:23:43 -0600 Started GET "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:43 -0600 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) An unauthorized connection attempt was rejected Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:43 -0600 Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:43 -0600 Started GET "/cable" for ::1 at 2017-03-07 14:23:53 -0600 ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations" Started GET "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:53 -0600 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) An unauthorized connection attempt was rejected Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:53 -0600 Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:23:53 -0600 Started GET "/cable" for ::1 at 2017-03-07 14:24:05 -0600 Started GET "/cable/" [WebSocket] for ::1 at 2017-03-07 14:24:05 -0600 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) An unauthorized connection attempt was rejected Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:24:05 -0600 Finished "/cable/" [WebSocket] for ::1 at 2017-03-07 14:24:05 -0600

products/_product.html.erb

<% @products.each do |product| %> 
  <div class="col-sm-2 col-md-4"> 
    <h3><%= link_to product.name, product %></h3> 
    <% if product.image_url.present? %> 
      <%= image_tag(product.image_url , class: "img-thumbnail") %> 
    <% end %>
    <br> <strong>Description<%= product.description %></strong> <br/>
    <strong>Colour:<%= product.colour %></strong> <br/> 
    <strong>Price: $ <%= product.price %></strong> <br/> 
    <%= link_to 'Show', product ,class:"btn btn-default"%> 
    <%= link_to 'Edit', edit_product_path(product), class:"btn btn-default" %> 
    <%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' }, class:"btn btn-default"%> 
    <% logger.debug "Product: #{product.name}"%> <br> <br> 
  </div> <!-- /col --> 
<% end %>
1
Please show your products/_product.html.erbEyeslandic
<% @products.each do |product| %> <div class="col-sm-2 col-md-4"> <h3><%= link_to product.name, product %></h3> <% if product.image_url.present? %> <%= image_tag(product.image_url , class: "img-thumbnail") %> <% end %>Jovanka
<br> <strong>Description<%= product.description %></strong> <br/> <strong>Colour:<%= product.colour %></strong> <br/> <strong>Price: $ <%= product.price %></strong> <br/> <%= link_to 'Show', product ,class:"btn btn-default"%> <%= link_to 'Edit', edit_product_path(product), class:"btn btn-default" %> <%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' }, class:"btn btn-default"%> <% logger.debug "Product: #{product.name}"%> <br> <br> </div> <!-- /col --> <% end %>Jovanka
@Iceman can you seeJovanka
@Jovanka, it is better if you update your original post with the code. Also, please include the code of the controller, where the variable products is being created.fabriciofreitag

1 Answers

1
votes

I found the problem looking into the source you provided. You were looping through the products two times. The first time in the ./app/views/products/index.html.erb and then again in ./app/views/products/_product.html.erb. The solution would be to remove the loop from outside the partial as such:

/app/views/products/index.html.erb

<div class="container-fluid">
  <div class="row">
      <%= render partial: "product" %>
  </div> <!-- row -->
</div> <!-- container -->