如何将背景图像设置为回形针附件网址?

时间:2015-09-20 03:45:30

标签: css ruby-on-rails paperclip background-image attachment

我无法获取回形针附件网址来设置背景图片的样式。以下是我认为:

  <% @auction.lots.each do |lot| %>
    <div class="lot-with-image" style="background-image: url('#{request.protocol}#{request.host_with_port}#{lot.image}'); width: 300px; height: 300px; border: 5px solid black"></div>
  <% end %>

这是html:

<div class="lot-with-image" style="background-image: url('#{request.protocol}#{request.host_with_port}#{lot.image}'); width: 300px; height: 300px; border: 5px solid black">

我也尝试了#{lot.image.url},但我得到了相同的结果。

如果有更好的方法来使用回形针来设置背景图像的样式,我对建议非常开放。提前谢谢。

2 个答案:

答案 0 :(得分:3)

<% @auction.lots.each do |lot| %>
    <div class="lot-with-image" style="background-image: url('<%= lot.image.url %>'); width: 300px; height: 300px; border: 5px solid black"></div>
<% end %>

答案 1 :(得分:0)

请改为:

<% @auction.lots.each do |lot| %>
    <div class="lot-with-image" style="background-image: url("<%= lot.image.url %>"); width: 300px; height: 300px; border: 5px solid black"></div>
<% end %>

这是简要摘要Show image in view