Dean
Dean

Reputation: 425

Rails - Use ENV variable in yml file

This is myfile.yml

this_is_key:
  - [<%= ENV['MY_KEY_NAME'] %>, 1]

It will return the error syntax, can not parse file.Now, i change like this:

this_is_key:
  - [my_key_here, 1]

No errors occurred. Somebody can tell me, how can i pass ENV variable in my file?

Upvotes: 1

Views: 1890

Answers (2)

kazuwombat
kazuwombat

Reputation: 1653

works by renaming .yml to .yml.erb in my case.

Upvotes: 0

Igor Drozdov
Igor Drozdov

Reputation: 15045

You can do it only if you parse the resulting yml file as an erb template:

YAML.load(ERB.new(File.read("myfile.yml")).result)

result method passes the current binding into template and renders the file according to the variables in the scope.

Here's an article about such experiments.

Upvotes: 2

Related Questions