Generating menus via simple data file

Working to get head around middleman. Trying simple test case as follows, but having issues

menu.yml:
menuItems:

  • menuItem:“Home”
    menuLink:"/"
  • menuItem:“Concept”
    menuLink:"/concept"
  • menuItem:“Design”
    menuLink:"/design"
  • menuItem:“Delivery”
    menuLink:"/delivery"
  • menuItem:“Gallery”
    menuLink:"/gallery"

Then in layout.erb: (with best * though not working* guess for loop and then expected result example without data)

		<ul class="top-nav">

			<% data.menu.menuItems.each do |m| %> 
			<li><%= link_to m[:menuItem], m[:menuLink] %></li>
			<% end %>
			

		</ul>
	
		<ul class="top-nav">
			<li><%= link_to  'Home', '/' %></li>
			<li><%= link_to 'Concept', '/concept/' %></li>
			<li><%= link_to 'Design', '/design/' %></li>
			<li><%= link_to 'Delivery', '/delivery/' %></li>	
			<li><%= link_to 'Gallery', '/gallery/' %></li>
		</ul>

So, question is how do I get the data to pull through when I have key/value pairs in yaml file?
Can get the simple friends example without key & value to work.

Thanks.

Is the yaml file valid ? http://yamllint.com

Yes - the yaml is valid.

Valid YAML! in green I get.

The general answer was that the code didn’t reflect the yaml structure. So I simplified the YAML file to fit:

--- 
- 
  menuItem: Home
  menuLink: /
- 
  menuItem: Concept
  menuLink: /concept
- 
  menuItem: Design
  menuLink: /design
- 
  menuItem: Delivery
  menuLink: /delivery
- 
  menuItem: Gallery
  menuLink: /gallery

it’ll work with

<ul class="top-nav">
<% data.menu.each do |m| %>
  <li><%= link_to m[:menuItem], m[:menuLink] %></li>
<% end %>
</ul>

Thanks very much for that. Clearly need to hit books more on yaml.

I don’t know if there is a book on YAML. What helped me figure out what was wrong was looking at these examples of data structures to see that your code expected to walk through a sequence of mappings (example 2.4). Your original code was fine, but the yaml file needed a space between the : and the value