link_to internal pages gives me an error

I am setting up a nav bar on a new project and for some reason I am drawing a blank on linking to internal pages.
My nav links look like this, but it gives me a “file not found” page.

<li><%= link_to 'Home', '/' %></li> <li><%= link_to 'About Us', '/about' %></li>

My pages are named with *.html.erb appended to the end. It works on another project I built with Middleman, but it’s been 6 months since coming back into it… Any help would be greatly appreciated. Thank you in advance.

I added .html to the end of ‘/about.html’ and that seemed to work. I guess my only question is why my other project didn’t need the html at the end…

Check config.rb on this project and your other project. My guess is that this project does not have

activate :directory_indexes

and your other project does. Here’s the documentation on directory indexes

@scottelundgren Image that :slight_smile: It’s the small things that get ya’.

Thank you for your help.

@scottelundgren OK here’s another brain twist… I’ve got this link setup

	  <ul class="nav navbar-nav navbar-right">
		<li><%= link_to 'Home', '/' %></li>
		<li><%= link_to 'About Us', '/about' %></li>
		<li><%= link_to 'Blog', '/blog' %></li>
		<li><%= link_to 'Services', '/services' %></li>
		<li><%= link_to 'Sustainability', '/sustainability' %></li>
		<li><%= link_to 'Green Clean', '/sustainability/gc2.html' %></li>
		<li><%= link_to 'Contact', '/contact.html' %></li>
	  </ul>

and all the links work without the .html appended except for the gc2.html page located in a sub-nav; it throws an error unless the .html is added. I know I am probably not using best practices. Think you can shed some light?

Thanks…again…

Based on the earlier thread and this code fragment I’m guessing that directory_indexes are on. What is the error?

is the gc2.html file in the sustainability directory?
Does the link work?
If not what is the path you are expecting? What does http://0.0.0.0:4567/__middleman/ show you was created?

@scottelundgren just a 404 error. Gc2 is in the sustainable directory…here is the output

I thought I would be able to go to priorityservices.net/sustainability/gc2 and it would default to it’s own generated index page. Does this provide clues? Thank you.

Yep! I suspect that gc2.html has directory_index: false in the front matter

directory_indexes in config.rb works globally for all content but it can be overridden locally per page

@scottelundgren

the only thing I have is

---
title: Green Cleaning
---

but I did notice that in config.rb I have activate :directory_indexes but not directory_index: true - should I have something else in config?

Thank you.

I was replying from my phone and messed up the syntax activate :directory_indexes is correct.

Remember with activate :directory_indexes Middleman is going to build a directory with the name of your source file for you and create a file in that directory called index.html unless you override that filename using the set :index_file directive. So…

You’re doing too much work for having source/sustainability/index.html.erb.

Rename source/sustainability/index.html.erb to source/sustainability.html.erb

Then source/sustainability/gc2.html.erb will be accessible via /sustainability/gc2/

@scottelundgren Thank you for the input… then would I be correct in thinking that the initial index page of a directory, i.e. source/sustainability.html.erb must be at root level, and then all pages that are part of a sub-directory would be placed inside - in this case, ‘sustinability’.

Thank you again; this is truly a whole new way of thinking, but more efficient.

Yes, the initial page has to be at root level. Glad to help.

@scottelundgren You rock!