Turbolinks with carrierwave images as CSS background-image

馋奶兔 提交于 2020-01-22 13:56:19

问题


I've been using turbolinks along this year but lately I'm getting this annoying bug. Images uploaded via carrierwave are loaded in the site with absolute URL's in the first request, but when you start browsing in the site via turbolinks, all carrierwave images change to relative paths. <%= image_tag "image.jpg %> elements work ok, but the images are loaded as CSS background-image, they don't appear. This apparently happens only on chrome (I have Versión 31.0.1650.57 m). I made a trace via console and all images are loaded in the document, so I went to the Inspector and disabled/enabled the property 'background-image' of the specific element and the magic happened: the image appeared.

I'm using rails 3.2.14, with turbolinks:

gem 'turbolinks', '1.3.1'
gem 'jquery-turbolinks', '2.0.1'

I already tested this on Firefox 25.0.1 and it works ok.

Any suggestion? Thanks


回答1:


I just figured out that if you use absolute url's for background images the bug dessapears. So this is how I call carrierwave images in my helper:

img = ProductImage.find(id) 
"#{request.protocol}#{request.host_with_port}#{img.photo}"

photo is the attribute used with carrierwave uploader.



来源:https://stackoverflow.com/questions/20051244/turbolinks-with-carrierwave-images-as-css-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!