I am not a fan of introducing a new variable, i.e. var rails_env = '<%= Rails.env %>' because it pollutes the global namespace. Do all JS files need this variable? Or all the features of JS?
I would use something similar to @Magne, but instead of creating a hidden div, I would just apply it to the body tag:
<body data-rails-env="<%= Rails.env %>">
Or in HAML (you use HAML, right ?!)
%body{ "data-rails-env" => Rails.env }
Then any script can pick it up:
$("body").data("rails-env")
source share