Links to home for existing site redesign

I’m redesigning an existing site, and want to put the draft redesign in a subfolder “newDraft”. All links work, except the link to the home page, the ‘root’ of the new design.

If I use:

<li><% link_to '/' do %>Home<% end %></li>

then the ‘Home’ link goes to the root of the old site.

I tried using a Base URL:

 <base href="http://www.website.com/newDraft" />

but that means that my live development env breaks because the styles and javascripts can’t be found.

Interesting edge case? Not intended to deploy within existing sites? Or, more likely, I’m missing something. Pointers appreciated.

I would suggest creating a new helper to simplify treating a subfolder as the root. Something like:

helpers do
  def new_site_link_to(url, *args, &block)
    super("/newDraft#{url}", *args, &block)
  end
end

Oh, interesting. Helpers, right.

It’s been a couple of years since I was deep into Ruby, and I’m not asking you to debug this for me, but can you suggest a link or pointer to where I could read up on what causes this kind of error?

super: no superclass method `new_site_link_to' for #<Middleman::Application:0x70093890773060>

One interesting thing might be the block in singleton class error from the _aside.html.erb partial:

/Users/mj/.rvm/gems/ruby-2.0.0-p0/gems/middleman-core-3.1.0.beta.3/lib/middleman-core/configuration.rb: in method_missing
          super...
/Users/mj/Dev/test-com/config.rb: in new_site_link_to
    super("/newDraft#{url}", *args, &block)...
/Users/mj/Dev/test-com/source/_aside.html.erb: in block in singleton class
        		<li><% new_site_link_to '/' do %>Home<% end %></li>...
/Users/mj/.rvm/gems/ruby-2.0.0-p0/gems/tilt-1.3.7/lib/tilt/template.rb: in call
      method.bind(scope).call(locals, &block)

I’ll take another look at it later tonight.

I couldn’t figure out the superclass error. Maybe I don’t have an assumed extension or gem available.

But as I was falling asleep, thinking, "We need a symbol for ‘home’ – a relative root rather than an absolute ‘/’ root – I realized that if I just linked to ‘index.html’, like every other link in the nav, it would solve my problem. And indeed it does.

This only works if all your html pages are in the same directory (no nested folders), so it’s not a general solution, but it works in the naive case. I post it here only for completeness.

So you can do this. In config.rb:

set :new_draft_home, "/newDraft/index.html"

And then in your templates:

<%= link_to new_draft_home, 'Home' %>

I’m also struggling with the same problem. I need to deploy our Middleman site to a subdirectory on the site, and I can’t seem to figure out a clean way to do this. Everything works great in development mode, but then when I deploy all the generated links (link_to, stylesheets, JS, etc.) fail because of the absolute references.

If I use the helpers idea, then things won’t work in development mode.

It seems that this would be a useful feature, and I’d be happy to help support for it, especially if someone could give me some tips on where that logic should best live.

Try adding this to config.rb.

set :relative_links, true

It’s mentioned here: http://middlemanapp.com/helpers/.