Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Dan Maliano
Dan Maliano
12,142 Points

Ruby - Sinatra build navigation from "pages" folder with ".each", what am I doing wrong?

I'm trying to output the "pages" directory as navigation, please help =)

(from Ruby track, last part - Sinatra, the final lesson - from the teacher notes)


version 1

wiki.rb

def nav
d = Dir.new("pages")
d.each  {|x| puts "#{x}" }
end 

get "/" do
  Mackenzie Steele  = nav
  erb :welcome
end

welcome.erb

<ul>
<li><a href="/<%= Mackenzie Steele  %>"><%= @m %></a></li>
</ul>


version 2

wiki.rb

def nav
d = Dir.new("pages")
d.each  {|x| puts "<li><a href=\"/#{x}\">#{x}</a></li>" }
end 

get "/" do
  @m  = nav
  erb :welcome
end

welcome.erb

<ul>
    <%= @m %>
</ul>

What am I doing wrong?