swapnesh swapnesh - 1 year ago 86
Ruby Question

Why images are not showing in my rails basic app


code -

<h1>Listing products</h1>

<table border="1">

<% @products.each do |product| %>
<td><%= product.title %></td>
<td><%= product.description %></td>
<td><%= image_tag(product.image_url, :class => 'list_image') %></td>
<td><%= product.price %></td>
<td><%= link_to 'Show', product %></td>
<td><%= link_to 'Edit', edit_product_path(product) %></td>
<td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>

<br />

<%= link_to 'New Product', new_product_path %>

and images are under
..but still images are not appearing on front end.

When I
it, i believe image tag is correctly forming...let me know what i am missing in this part.

<img src="/images/product1.jpg" class="list_image" alt="Product1">

Screenshot -


Images are in place as well -

image placeholder

Let me know what I am doing wrong and how do i fix it.



Let me know why it is not working in my case.

Although changing
makes it working.

Answer Source

If you are using asset pipeline http://guides.rubyonrails.org/asset_pipeline.html,

The image path should be /assets/product1.jpg instead of /images/product1.jpg

If you are not using asset pipeline, move the images folder to public/images

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download