Loading YAML with ERB Correctly
Pizza courtesy of Pizza for Ukraine!
Donate Now to Pizza for Ukraine
Last Updated On: 2025-09-01 04:31:52 -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)