Consider we have an ENV defined in the Rails .env file and we want to use that in the .html.slim file under the Javascript section
.env file
NUMBER_TO_MULTIPLY: 2
filename.html.slim
javascript:
$(document).ready(function() {
var count = selectedRows.length; // Gives me value as 3
var totalCount = count * "#{ENV['NUMBER_TO_MULTIPLY']}" // Should give me value as 3 * 2 = 6
alert(totalCount) // Produces me 0 as the result
}
I tried Rails.env but it give the value as "development" apart from that I am not able to access any value from the ENV. Any help would be greatly appreciated.
.envfiles arent supported by Rails out of the box.For development / test the dotenv gem is an alternative.
For production it depends on the hosting environment.