cphil cphil - 5 months ago 38
CSS Question

How can I set the background-image to a paperclip attachment url?

I'm having trouble getting the paperclip attachment URL to style a background image. The following is in my view:

<% @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 %>


This is the 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">




I also tried
#{lot.image.url}
as well, but I got pretty much the same result.

If there is a better way to use paperclip to style the background-image, I'm very open to suggestions. Thanks in advance.

Answer
<% @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 %>
Comments