5 minute code: Multipage static pages – Ruby/Rack

Doing a static page in Heroku with Ruby/Rack is a breeze. However, when we tried to create a page with tabs that would each link to different content, the URL at the top would be correct but nothing would happen.

Turns out there’s a quick fix. The only difference I did was a tiny bit at the bottom, with the arguments passed to File.open:

use Rack::Static,
  :urls => ["/images", "/js", "/css"],
  :root => "public"
run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public' + env['PATH_INFO'], File::RDONLY)
    ]
}

This will then load the public/aboutus.html & public/contact.html, as originally desired.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>