问题
Is there anyway I can get an environment variable (like an API key) to appear inside JS/Coffee using Rails 3.1?
回答1:
You can rename your file.js to file.js.erb and use ruby to access ENV:
<% do_something_with ENV['key'] %>
some_js_code
来源:https://stackoverflow.com/questions/9082465/environment-variables-in-js-coffeescript