Selectively disable asset.digest in Rails 3, so an external site may include a stylesheet

Purpose:

I would like the Tumblr blog to pull CSS from the Rails application resource directory.

This means that I can use SASS, Compass and other CSS to create the style.

It also means that if something updates in low-level CSS, tumblr.css will regenerate along with regular cap deploy , and the appearance of Tumblr will automatically change.

Problem:

The Rails 3 resource pipeline adds a hash to the file name, for example:

tumblr-c6ec969ce054623163b9404f6c8330e9.css

Therefore, the Tumblr template cannot include it unless I manually update the URL every time it changes.

Is there a way to selectively disable asset.digest for a single file, or explicitly create a single CSS file from SASS without going through the entire asset pipeline? Or maybe create an automatic alias or something else?

+7
source share
2 answers

You do not have to turn off digests at all.

When Rails precompiles assets, it adds digests to all files. However, it also creates identical files without digests. Therefore, both of the following files load the same css:

  • tumblr-c6ec969ce054623163b9404f6c8330e9.css
  • tumblr.css

If you check the public/assets directory after preliminary compilation, you will see both files.

Hope this helps.

+5
source

In Rails 4, it seems that asset precompilation no longer performs both digest and non-digest file names, only digest files are compiled. The best option now to precompile assets without a digest hash is to use Non Stupid Digest gems:

 https://github.com/alexspeller/non-stupid-digest-assets 

Hopefully they will add this to the Rails project as a standard feature in Rails 5.

+3
source

All Articles