Is it best to generate an
application.js.erb which is dynamic based on the environment we are running or am I missing something?
In your application layout, you can add environment specific js file like this:
Or more cleaner way:
You can achieve the same result in another way by creating a specific js file and requiring that in application.js.erb:
<%= Rails.env.production? ? 'productionConf();' : 'regularConf();' %>
//= require env_config //= require jquery ...
Instead of loading a different js file, set a variable based on the different environment
I would recommend using gon Its an easy way of getting rails variables into js.
After setting up, do something in your controller like:
before_filter :set_gon_env def set_gon_env gon.rails_env = ENV['RAILS_ENV'] == 'development' ? "dev" : "not dev" end
©2020 All rights reserved.