ruby-on-rails - rails : Why images are not showing in my rails basic app

标签 ruby-on-rails ruby ruby-on-rails-3 image

我的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 下..但是前端没有显示静态图像。

当我 Firebug 它时,我相信图像标签是正确形成的...让我知道我在这部分缺少什么。

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

截图 -

screenshot

图片也到位了-

image placeholder

让我知道我做错了什么,我该如何解决。

编辑

github.com/swapnesh/depot

请告诉我为什么它在我的案例中不起作用。

尽管更改 /images/product1.jpg To /assets/product1.jpg 使其正常工作。

最佳答案

如果您正在使用 Assets 管道 http://guides.rubyonrails.org/asset_pipeline.html ,

图片路径应该是/assets/product1.jpg而不是/images/product1.jpg

如果您不使用 Assets 管道,请将图像文件夹移动到 public/images

关于ruby-on-rails - rails : Why images are not showing in my rails basic app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15827763/

相关文章:

ruby-on-rails - Mongoid 版本控制范围

ruby-on-rails - 由另一个用户添加用户

ruby - 如何仅通过多个对象的唯一组合进行迭代?

ruby-on-rails - 在 ruby​​ on rails 网站上运行 XNA 游戏

ruby-on-rails - 在 Rails 3.x 应用程序中禁用 Cookie

ruby-on-rails - 如何使用 Minitest 在设置方法中 stub ?

ruby-on-rails - rake db :create in Rails 的段错误

安装 compass gem 后 ruby​​ 1.9.1 错误

ruby - 如何在 Bluehost 上安装特定版本的 Ruby 和 Rails?

ruby-on-rails - Rails 3 迁移更改浮点长度/小数