0

我的数据库中存储了 url,我无法将它们用作卡片的背景图像。

在数据库中有一个带有“图像”列的“鸡尾酒”表,其中将 url 存储为字符串

<% @cocktails.each do |cocktail| %>
  <div { background-image: url(<%= cocktail.image %>) }></div>
<% end %>

在导航器检查器中看起来像这样:

<div {="" background-image:=""url(https:="" weatherinternal.com="" wp-content="" uploads="" 2019="" 04="" book-claims-to-shed-light-on-john-belushis-final-drug-fueled-hours.jpg)="" }=""></div>

“/”似乎已被删除并且图像不显示

当我写<%= cocktail.image %>它时,它会以正确的格式显示链接,并使用 a<img>或 rails 图像助手正确显示图像。

我猜在导航器中的 html 应该看起来像这样

<div {="" background-image:=""url(https:/weatherinternal.com/wp-content/uploads/2019/04/book-claims-to-shed-light-on-john-belushis-final-drug-fueled-hours.jpg)="" }=""></div>
4

0 回答 0