无法让自定义错误页面在 Padrino 中工作

Can't get custom error pages to work in Padrino

我开始用padrino建立一个网站。目前我的应用程序的主要 class 是世界上最简单的东西:

class App < Padrino::Application
  enable :sessions

  get :index do
    send_file 'public/view/index.html'
  end

  error 404 do
    send_file 'public/view/errors/404.html'
  end
end

所以视图只是 htmls - 其背后的想法是使用 angularjs 来呈现 rest api 提供的所有东西。我想这是相当标准的。

我的问题是 - 虽然它可以很好地呈现主页 (localhost:3000/),但自定义错误根本不起作用;假设我尝试 localhost:3000/test - 而是呈现标准 "Sinatra doesn’t know this ditty" 页面。

我是 运行 padrino 0.12.4 和 WEBrick 1.3.1。我在这里做错了什么?

我相信这里发生的事情是,当您转到 localhost:3000/test 时,您的 Sinatra 应用正在寻找 App Controller 下的 "test" 操作。显然这个动作没有被发现,因为它没有被列为路线!因此,如果找不到 diddy,请明确告诉 Sinatra return 一个 404 页面:

error Sinatra::NotFound do
  content_type 'text/plain'
  [404, 'Not Found']
end