rails/sass-rails — Issue #93: asset_host embedded in CSS is unnecessary and causes issues in different environments
Author: mattheworiordan
Created: 2012-02-14 15:30:09+00:00
State: open

In my SCSS files, I am using a style like this:

#thing {
background: url(image-path('my-background.png'));
}

In development on my local server, this CSS is rendered correctly as:

#thing {
background: url("/assets/my-background.png"));
}

However, when I compile the assets using ```rake assets:precompile```, Rails automatically uses the production environment variables to produce the assets and compile the CSS. As I am using an asset host in production ```config.asset_host = "mycdn.com"```, when sass-rails processes the image-path or image-url helpers within my CSS, they render the full path including the CDN domain for the production environment as follows:

#thing {
background: url(//mycdn.com/assets/my-background-[fingerprint].png);
}

The problem is of course that in my staging environment, loading the assets from my production environment is incorrect. So the assets don't load correctly, and I have no way around this issue. So I have two questions:

* Why does sass-rails using an absolute path for the asset helpers image-url and image-path. Surely if the assets are being served from the stylesheets that are housed on the same CDN (asset host), then absolute paths are unnecessary?
* Assuming you don't want to change the behaviour from above, is there some easy way to introduce a helper that does not use the absolute path with domain?

This problem is unfortunately quite a big one for me as my staging environment since moving to Sprockets no longer works. I have taken a quick look at the /sass/rails/helpers.rb file, but unfortunately I'm unclear what ```options[:customer][:resolver]``` represents so have struggled to find a solution.

Your help would be greatly appreciated.

Matt