如何将背景图像设置为回形针附件 url?
How can I set the background-image to a paperclip attachment url?
我无法获取回形针附件 URL 来设置背景图片的样式。以下是我的看法:
<% @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}
,但我得到的结果几乎相同。
如果有更好的方法来使用回形针来设置背景图像的样式,我非常愿意接受建议。提前致谢。
<% @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 %>
请更改为:
<% @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
我无法获取回形针附件 URL 来设置背景图片的样式。以下是我的看法:
<% @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}
,但我得到的结果几乎相同。
如果有更好的方法来使用回形针来设置背景图像的样式,我非常愿意接受建议。提前致谢。
<% @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 %>
请更改为:
<% @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