librelist archives

« back to archive

Re: [nesta] Create a custom error page? (#82)

Re: [nesta] Create a custom error page? (#82)

Graham Ashton
2011-11-28 @ 10:45
On 23 Nov 2011, at 21:01, Benjamin Charity wrote:

> I feel like I'm going crazy...this is usually a fairly simple task.  
This is my first foray into Nesta so I may have missed it?

I haven't written about it on the site, but I can see that's something 
worth doing.

Because Nesta is written in Sinatra, it's using Sinatra's approach to 404 pages.

Sinatra handles 404 pages with some code like this:

    not_found do
      'This is nowhere to be found.'

To define this in Nesta you need to create an app.rb file in your project,
and add something like this to it:

    module Nesta
      class App
        not_found do
          'Text of error page'

If you want to render a special template for it, you could put this in the
not_found block:

    not_found do
      cache haml(:my_error_page)

You'd need a views/my_error_page.haml file to get that last example to work.

More info on Sinatra's handlers can be found here: