【发布时间】:2020-07-15 01:26:33
【问题描述】:
我正在尝试显示一张图片,但它不起作用。请注意,这是我的第一个 Ruby 应用程序(自编程产品)并且我克隆了 Repo,所以如果我没有从一开始就提供所有必需的信息或错过一个相当简单的疏忽,我提前道歉。
这是我的图片未显示的屏幕截图:
我在 Illustrator 中创建了图形并将其导出为 png。然后我将它添加到正确的项目文件夹中。图片名为 AIQtshirt.png,代码如下:sn-p:
{
'count' => 15,
'html' => 'AutonomIQ<br>T-shirt',
'class' => 'three',
'image' => ActionController::Base.helpers.asset_path(
'refer/AIQtshirt.png')
}
事实上,当我使用之前存在的图像时(来自我克隆的 Repo),它可以工作。此图像称为 truman.png,它与我放置 AIQtshirt.png 文件的文件夹位于同一文件夹中:
这是我克隆它时使用存储库中初始占位符的代码 sn-p:
{
'count' => 15,
'html' => 'AutonomIQ<br>T-shirt',
'class' => 'three',
'image' => ActionController::Base.helpers.asset_path(
'refer/truman.png')
}
如果查看 repo 更容易,可以在此处引用。 https://github.com/harrystech/prelaunchr
我可以想象在 repo 的另一个文件夹中我忘记了做某事。
这是我使用 cmets 中提供的代码编辑 repo 时得到的字符串:
提前感谢您的帮助!
更新:这里是代码:
<% stops.each do |stop| %>
<li class="product brandon <% if stop["selected"] %>selected<% end %> <% if stop["class"] == 'five' %>last<% end %>">
<div class="circle"><%= stop["count"] %></div>
<div class="sep"></div>
<p><%= stop["html"].html_safe %></p>
<div class="tooltip">
<img src="<%= stop["image"] %>" height="254">
</div>
【问题讨论】:
-
嗨 sjmario38,是否可以共享图像的路径以确保它位于正确的位置?
-
嗨@Abhinay我提前为我的天真道歉。路径是指我的图像在 GitHub 存储库中所在的文件夹吗?如果是这样的话:/Documents/GitHub/prelaunchr/app/assets/images/refer/ 我希望这会有所帮助。
标签: ruby-on-rails ruby png imagecreatefrompng