Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment Variables in JS/Coffeescript

Is there anyway I can get an environment variable (like an API key) to appear inside JS/Coffee using Rails 3.1?

like image 254
cjm2671 Avatar asked Jun 18 '26 11:06

cjm2671


1 Answers

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

<% do_something_with ENV['key'] %>
some_js_code
like image 163
Ineu Avatar answered Jun 21 '26 00:06

Ineu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!