Environment variables in JS / Coffeescript

Anyway, can I get an environment variable (e.g. API key) to appear inside JS / Coffee using Rails 3.1?

+2
source share
1 answer

You can rename file.js to .js.erb and use ruby ​​to access ENV:

<% do_something_with ENV['key'] %> some_js_code 
+8
source

Source: https://habr.com/ru/post/1243984/


All Articles