So in my app i have a card where i want to dynamically set the background image via ActiveStorage like so:
<div class="card" style="background-image: url(<%= rails_blob_path(post.images.first) %>)">
</div>
however, the image is not visible. Inside chrome i also get in the element.style property "invalid type property"
as an error.
If i inspect the card element, the url is loaded like so:
`background-image: url(/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9be6ec89650623cc4a22214c34635f2924f8feea/Frame%20(1).png)`
Taking the url and adding localhost:3000 to it loads the image:
localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9be6ec89650623cc4a22214c34635f2924f8feea/Frame%20(1).png
Rendering the image normally inside an img tag works fine:
<%= image_tag(post.images.first) %>
Also, changingrails_blob_path
to rails_blob_url
makes no difference at all. The only change is that there is a localhost:3000 added to the url in rails_blob_url:
http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9be6ec89650623cc4a22214c34635f2924f8feea/Frame%20(1).png
Adding a height/width to the card class results also in no difference.
Here is a reference i've found, seems like they are using the same approach as i do: Ruby on rails 5.2 - background image with active storage
Any ideas where the problem might be?
Thanks in advance everyone!
Greetings!