cjm2671
cjm2671

Reputation: 19496

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?

Upvotes: 3

Views: 5532

Answers (1)

Ineu
Ineu

Reputation: 1373

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

<% do_something_with ENV['key'] %>
some_js_code

Upvotes: 9

Related Questions