Scott's Recipes Logo

Loading YAML with ERB Correctly


Please note that all opinions are that of the author.


Pizza courtesy of Pizza for Ukraine!

Donate Now to Pizza for Ukraine

 

Last Updated On: 2025-10-13 07:27:40 -0400

I recently had to refactor a database.yml file which had multiple config blocks all with ERB calls. Here’s an example:

The magic here is:

FIXTURE_CONFIG = YAML.load(ERB.new(File.read(“#{Rails.root}/path_to_your_file.yml.erb”)).result)