Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to a Rails asset without fingerprint?

In Rails, my assets have fingerprints added to them, e.g.

mysite.com/assets/something/base-216123123asdfasd20a.css

Unfortunately, if I want to link to this from another site (like a blog) I can't rely on the fingerprint.

Is there a configuration setting I can set so that I can access files without knowing their fingerprint? (While still keeping the fingerprint for normal Rails usage; this would just be used for special cases)

I don't want to do one-off things like creating a route for a specific asset, because I'll need it for many assets.

like image 532
user3179047 Avatar asked Nov 01 '22 17:11

user3179047


1 Answers

The simplest way is to put the files directly into the public folder:

- public
-- your_file.js

This would then have to be called by referencing your URL directly = http://domain.com/your_file.js

This is only really advisable for files which you want to remain static (such as widget JS or similar).


Non Digest Assets

Alternatively, you may wish to try a gem I've never used before called non-stupid-digest-assets - a gem which allows you to determine which files are "fingerprinted" and which are not.

I've never used this gem, so cannot comment on its effectiveness, but it looks like it will give you the ability to save certain assets without their fingerprinted name. This means that you'll still be able to call them using the various asset path helpers which are available in Rails, as well as giving others a direct reference for the file:

#config/initializers/non_digest_assets.rb
NonStupidDigestAssets.whitelist = ["your_file.js"]

You'll then be able to call asset_path("your_file.js")

like image 65
Richard Peck Avatar answered Nov 15 '22 07:11

Richard Peck