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

查看:47
本文介绍了Rails:为什么我的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时,我认为图像标签正确形成了……让我知道这部分我所缺少的.

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.

编辑

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

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