I am trying to upgrade a Rails 3 application to use Rails 3.1, and as part of this, I am using a new asset pipeline. Until now, everything works for me separately from one rather annoying problem that I can not solve.
The application and all its assets work fine in development, but during production, it is deployed in a sub-URI using Passenger ( http://the-host/sub-uri/ ). The problem is that the resources are precompiled during deployment, and one of my CSS files (well, this is a .css.scss file) uses the image-url helper from the sass-rails gem. Because during the pre-compilation process, the paths are hard-coded into a pre-compiled CSS file, sub-uri are not taken into account:
In my .css.scss file:
body { background-image: image-url("bg.png"); }
The result in the compiled file application-<md5-hash-here>.css :
body { background-image: url(/assets/bg.png); }
What you need to do to make it work correctly:
body { background-image: url(/sub-uri/assets/bg.png); }
Is this scenario too much? If so, I will need to revert to the old non-asset path and just execute my images and CSS with public . However, it seems that something had to be thought and decided ...? Am I missing a solution?
Edit 1: It should be noted that using the erb solution gives the same result as expected.
Edit 2: in response to Benoit Garret's comment
No, the problem is not related to config.assets.prefix . I tried setting this value (to /sub-uri/assets , not the default /assets ), but it turned out that it was wrong - it looks like this parameter already refers to the root of the Rails application, and not to the server, Removing this (and thus returning to the default) fixed all the strange problems that caused (and there were many, all the assets ended up in /sub-uri/sub-uri/assets ), it was very strange). The only problem is that the image-url helper and friends do not pick up sub-URIs when they are precompiled. Needless to say, this is logical, because when it is precompiled, he could not know that when he works under the Passenger, he will be configured in this way. My question is how to report this and thus lead to the correct paths in the precompiled result. If itβs really possible,
My current workaround is to link to iamge in CSS as follows: url(../images/bg.png) and put it in a non-pipelined location public/images . It is hardly ideal, since it does not benefit from fingerprints and everything that the pipeline provides.