Rails:为什么我的Rails基本应用程序中没有显示图像 [英] Rails: Why images are not showing in my rails basic app
问题描述
我的index.html.erb
代码-
<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 %>
并且图像在app\assets\images
下..但是静止图像没有出现在前端.
and images are under app\assets\images
..but still images are not appearing on front end.
当我Firebug
时,我认为图像标签正确形成了……让我知道这部分我所缺少的.
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">
屏幕截图-
图像也就位-
让我知道我在做错什么以及如何解决.
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.
尽管将/images/product1.jpg
更改为 /assets/product1.jpg
仍可以使它起作用.
Although changing /images/product1.jpg
To /assets/product1.jpg
makes it working.
推荐答案
如果您正在使用资产管道 http://guides.rubyonrails .org/asset_pipeline.html ,
If you are using asset pipeline http://guides.rubyonrails.org/asset_pipeline.html,
图像路径应为/assets/product1.jpg
而不是/images/product1.jpg
如果您不使用资产管道,请将images文件夹移至public/images
If you are not using asset pipeline, move the images folder to public/images
这篇关于Rails:为什么我的Rails基本应用程序中没有显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!