swapnesh swapnesh - 3 months ago 12
Ruby Question

Why images are not showing in my rails basic app

my

index.html.erb
code -

<h1>Listing products</h1>

<table border="1">

<% @products.each do |product| %>
<tr>
<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>
</tr>
<% end %>
</table>

<br />

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


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

When I
Firebug
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 -

screenshot

Images are in place as well -

image placeholder

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

EDIT

github.com/swapnesh/depot

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

Although changing
/images/product1.jpg
To
/assets/product1.jpg
makes it working.

Answer

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

Comments