librelist archives

« back to archive

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

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

From:
Graham Ashton
Date:
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.'
    end

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'
        end
      end
    end

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)
    end

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:

http://www.sinatrarb.com/intro#Error%20Handling