In my settings.yml file I have several config vars, some of which reference ENV[] variables.
for example I have ENV['FOOVAR'] equals WIDGET
I thought I could reference ENV vars inside <% %> like this:
Settings.yml:
default: cv1: Foo cv2: <% ENV['FOOVAR'] %>
in rails console if I type
> ENV['FOOVAR'] => WIDGET
but
> Settings.cv1 => Foo (works okay) > Settings.cv2 =>nil (doesn't work???)
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file).
To pass environment variables to Ruby, simply set that environment variable in the shell. This varies slightly between operating systems, but the concepts remain the same. To set an environment variable on the Windows command prompt, use the set command.
use following:-
default: cv1: Foo cv2: <%= ENV['FOOVAR'] %>
The above solution did not work for me. However, I found the solution on How do I use variables in a YAML file?
My .yml file contained something like:
development: gmail_username: <%= ENV["GMAIL_USERNAME"] %> gmail_password: <%= ENV["GMAIL_PASSWORD"] %>
The solution looks like:
template = ERB.new File.new("path/to/config.yml.erb").read processed = YAML.load template.result(binding)
So when you introduce a scriptlet tag in .yml file, it is more of erb template. So read it as a erb template first and then load the yml as shown above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With