I am trying to dynamically create divs in my Rails app through javascript. However, the divs background images are not linking correctly. I know that Rails will search through images for preloaded css files. For instance, in my main css file I simply have
html, body{
background-image:url('bg.png');
}
However, when I create divs dynamically with the following code.
$("<div>").addClass("icon").css("background-image", "url(" + this.model.get('icons')[i] + ")").appendTo(this.el);
It doesn’t find the images. Do I have to use relative urls such as ‘/assets/images/…’?
Any help is very much appreciated. Thanks!
It turned out that I had to set the background image to
So apparently, Rails stores all images in just /assets/ as opposed to /assets/images/.