Open cloudhead opened 14 years ago
I'm guessing there's no way to customize the Kansas message?
Read above : )
Fixed in evaryont/toto@32b4d9ba75c0bfb99bcc2a60e24f618bfb929fde
To use it, just add set :error_page lambda { |code| "lol you got an error (#{code})" }
to your config.ru
Nice! But can it display a custom page instead?
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.
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>
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..
How could we render the 404 page with existing layout?
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
ariejan, how about using ERB?
@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"))
@ariejan, I got an error because I have to pass binding object to ERB#result method instead of string.
The easiest way is to:
# ...
set :error, lambda {|code|
ERB.new(File.read("templates/pages/error-#{code}.rhtml")).result
}
# ...
Current workaround: patch
Site#http
:http://github.com/cloudhead/toto/blob/master/lib/toto.rb#L110-112