I’m use Rails 3.2 built in sprockets functionality to compile static assets. Is it possible to compile javascript with environment specific variables?
So I would like to do something like this
/assets/javascripts/myfile.js
//lots of code
script.src =
('https:' == document.location.protocol ? 'https://' : 'http://') +
'some.metrics.site/projects/<%=ENV_SPECIFIC_TOKEN%>.js';
//lots of other code
Sprockets lets you append any number of preprocessors to a filename. Add a
.erbto the end, and it will be first interpreted as ERB and then output as a JavaScript file.mv assets/javascripts/myfile.js assets/javascripts/myfile.js.erbCheck out the Rails Asset Pipeline guide on JavaScript/CoffeeScript and ERB.