Iterate through yaml file produce nil:Class

My yaml content: events.yml > https://gist.github.com/visualisierte/6642199

Hello,

i want to iterate over a yaml file to fill HTML markup with content.

But when i do

- data.events.each do |year, event|
  %h3.articleSubheadline
    = year #works perfectly
  .timeBar
    .raceSection
      - event.each do |name, race| #produce the error
        = name

I get the following error:

undefined method `each’ for nil:NilClass

Thank you!

I found the solution.

Can you post the solution here in case someone else runs into the same problem?

This was my yaml file:

2012:
  event1
  event2
  event3
2011:

The problem was the empty ‘2011’. So this produced the nil:Class. the solution was to remove it.

Is it possible to get an index of the loop? I’ve tried each_with_index but that seems to stop the ability to parse the yaml properly.

@paulmsmith1 each_with_index should work fine – can you post an example of failing YAML?