Ruby on rails RubyonRails-图像不显示
我正在跟随一个关于点的教程,我的图像只是没有显示出来 这些图像位于app/assets/images文件夹中,扩展名为.jpg 有关守则如下: index.html.erbRuby on rails RubyonRails-图像不显示,ruby-on-rails,Ruby On Rails,我正在跟随一个关于点的教程,我的图像只是没有显示出来 这些图像位于app/assets/images文件夹中,扩展名为.jpg 有关守则如下: index.html.erb <% if notice %> <aside id="notice"><%= notice %></aside> <% end %> <h1>Products</h1> <table> <tfoot>
<% if notice %>
<aside id="notice"><%= notice %></aside>
<% end %>
<h1>Products</h1>
<table>
<tfoot>
<tr>
<td colspan="3">
<%= link_to 'New product', new_product_path %>
</td>
</tr>
</tfoot>
<tbody>
<% @products.each do |product| %>
<tr class="<%= cycle('list_line_odd', 'list_line_even') %>">
<td class="image">
<%= image_tag image_url(product.image_url, class: 'list_image') %>
</td>
<td class="description">
<h1><%= product.title %></h1>
<p>
<%= truncate(strip_tags(product.description), length: 80) %>
</p>
</td>
<td class="actions">
<ul>
<li><%= link_to 'Show', product %></li>
<li><%= link_to 'Edit', edit_product_path(product) %></li>
<li>
<%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
</li>
</ul>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= image_tag 'assets/7apps.jpg' %>
<%= image_url 'assets/7apps.jpg' %
最后两段代码只是我在试验我在堆栈中搜索的不同答案,它根本不适合我。
如果有帮助:
问题:在没有显示图像的地方,我到底做错了什么
编辑:在Julien的帮助下,代码的图像现在出现了
还有来自Julien的循环代码:
<td class="image">
<%= image_tag product.image_url, class: 'list_image' %>
</td>
令人烦恼的是,products表的图像仍然无法工作。我附上了一张图片
这是项目的数据库:
Product.create!(title: 'Seven Mobile Apps in Seven Weeks',
description:
%{<p>
<em>Native Apps, Multiple Platforms</em>
Answer the question “Can we build this for ALL the devices?” with a
resounding YES. This book will help you get there with a real-world
introduction to seven platforms, whether you’re new to mobile or an
experienced developer needing to expand your options. Plus, you’ll find
out which cross-platform solution makes the most sense for your needs.
</p>},
image_url: '7apps.jpg',
price: 26.00)
所以我希望这对product.image\u url来说是有意义的 您不需要在路径中包含“资产/”:
<%= image_tag '7apps.jpg' %>
嗨,朱利安,谢谢你。我现在已经更新了我的信息,解释了图片的url。有趣的是,代码的第一部分是有效的,但是当我使用for循环代码时,它仍然不能工作。检查生成的html的源代码中缺少的图像,图像的src属性是什么样子的?嗨,Julien,这很有趣!我已经检查了src属性,就是这样:所以当我点击链接时,图像会加载到一个单独的窗口中,但它仍然不会出现在实际的网页上。我应该在这里做什么?看起来图像很好,所以我想问题可能是图像只是隐藏了,list_image类的CSS是什么?Hi Julien,.image CSS显示:无,我已经把它删除了,现在图片出现了!我写这篇文章是因为教程中说要在移动设备上隐藏,但显然这不起作用。非常感谢你的帮助,你是个救命恩人
<%= image_tag product.image_url, class: 'list_image' %>