Giter Club home page Giter Club logo

Comments (13)

 avatar commented on July 3, 2024

I'm guessing there's no way to customize the Kansas message?

from toto.

cloudhead avatar cloudhead commented on July 3, 2024

Read above : )

from toto.

nogweii avatar nogweii commented on July 3, 2024

Fixed in nogweii/toto@32b4d9b

To use it, just add set :error_page lambda { |code| "lol you got an error (#{code})" } to your config.ru

from toto.

ariejan avatar ariejan commented on July 3, 2024

Nice! But can it display a custom page instead?

from toto.

nogweii avatar nogweii commented on July 3, 2024

Not as easily as you may like, though you can use the go() method, so I think (this is just off the top of my head) go "/error/#{code}.html" should work, if you want to use static pages.

Of course, you can use go in any manner, redirecting to any (local) URL.

from toto.

davejacobs avatar davejacobs commented on July 3, 2024

I get the following when I try to use go "/error/404" (which I can navigate to directly, so I know my page works):

NoMethodError at /2010/04/01/this-is-a-test4
undefined method 'go' for #<Toto::Config:0x10172a6f8>

from toto.

cloudhead avatar cloudhead commented on July 3, 2024

This is now official, and the setting is just called :error

For custom pages, you could probably just load the file with File.read("public/#{code}.html") or something similar..

from toto.

samnang avatar samnang commented on July 3, 2024

How could we render the 404 page with existing layout?

from toto.

ariejan avatar ariejan commented on July 3, 2024

Try this (I'm using HAML):

set :error do |code|
  ::Haml::Engine.new(File.read("templates/pages/#{code}.haml"), :layout => 'layout', :format => :html5, :ugly => true).render("templates/layout")
end

from toto.

samnang avatar samnang commented on July 3, 2024

ariejan, how about using ERB?

from toto.

ariejan avatar ariejan commented on July 3, 2024

@samnang - I don't use ERB, but it could be something like this:

ERB.new(File.read("templates/pages/layout.rhtml")).result(File.read("templates/pages/#{code}.rhtml"))

from toto.

samnang avatar samnang commented on July 3, 2024

@ariejan, I got an error because I have to pass binding object to ERB#result method instead of string.

from toto.

ixti avatar ixti commented on July 3, 2024

The easiest way is to:

  # ...
  set :error, lambda {|code|
    ERB.new(File.read("templates/pages/error-#{code}.rhtml")).result
  }
  # ...

from toto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.