为什么图像没有显示在我的rails基本应用程序中 [英] Why images are not showing in my rails basic app

查看:171
本文介绍了为什么图像没有显示在我的rails基本应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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 时,我相信image tag正确形成...让我知道我在这部分缺少的东西。

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">

屏幕截图 -

图片已到位好吧 -

Images are in place as well -

让我知道我做错了什么以及如何解决。

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

编辑

github.com/swapnesh/depot

让我知道为什么它在我的情况下不起作用。

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基本应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆