I’m trying to generate html files based on an ERB template with data
pulled from yaml files.
My code looks like this:
listing_data = Dir[’…/data/*’]
listings = []
listing_data.each do |file|
listing = File.open(file) { |data| YAML::load(data) }
listings << Listing.new(listing)
end
listing_template = ERB.new(File.read(‘listing.rhtml’))
listings.each do |listing|
File.open("…/homes/#{listing.file_name}.html", ‘w’) { |file|
file.write(listing_template.result(binding)) }
end
The problem that I am having is only the first listing is generated
along with an error: “no such file or directory” for the second one.
I have spent a couple of hours looking into it and trying different
things, but I’m just not able to figure it out. I know everything is in
place because the first listing gets generated just fine, but why
doesn’t it loop through the rest? If anybody can help me out that would
be amazing.