Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Can';无法在Padrino中使用自定义错误页_Ruby_Sinatra_Padrino - Fatal编程技术网

Ruby Can';无法在Padrino中使用自定义错误页

Ruby Can';无法在Padrino中使用自定义错误页,ruby,sinatra,padrino,Ruby,Sinatra,Padrino,我开始和帕德里诺建立一个网站。目前,我的应用程序的主类是世界上最简单的东西: 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 class-App

我开始和帕德里诺建立一个网站。目前,我的应用程序的主类是世界上最简单的东西:

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
class-App
因此,视图只是htmls——其背后的思想是使用angularjs呈现RESTAPI提供的所有内容。我想这是相当标准的

我的问题是——尽管它可以很好地呈现主页(localhost:3000/),但自定义错误根本不起作用;假设我尝试使用localhost:3000/test,而是呈现标准的“Sinatra不知道这首曲子”页面


我正在用WEBrick 1.3.1运行padrino 0.12.4。我做错了什么?

我相信这里发生的事情是,当你转到localhost:3000/test时,你的Sinatra应用程序正在你的应用程序控制器下寻找“test”操作。显然,找不到此操作,因为它未列为路由!因此,如果没有找到diddy,请明确告诉Sinatra返回404页:

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

实际上是的,只是用“Sinatra::NotFound”替换“404”就完全符合我的要求。