Saturday, 17 August 2013

Rails Asset Pipeline Paths In Runtime Javascript

Rails Asset Pipeline Paths In Runtime Javascript

I have a JavaScript file that consumes a JSON file generated from a rails
model and placed into the page by a controller.
Within this JSON file are a number of nodes, each with an id which I need
to take and convert to image paths. In development I know where the images
will be so I can loop through the do:
var imagePath = 'some/path/'+node.id+'.png';
However I am using Fingerprinting, so on staging and production I need a
way to resolve this path to a fingerprinted path.
So far as I can see I need to expose a map of paths - fingerprinted paths
so I can effectively do something like this:
var fingerprintedImagePath = fingerprintedPathsMap[imagePath];
In order to do this I need access to the manifest or whatever Rails stores
the manifest as from within either my controller or within the view
(inside an .erb tag).
How can I access a list of fingerprinted files? Or is there a better way
of giving JavasScript access to asset paths that will only be known
client-side.

No comments:

Post a Comment