Environment Variables in JS/Coffeescript

百般思念 提交于 2019-12-12 16:26:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!