Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 我如何处理Sinatra中的Mongoid错误?_Ruby_Sinatra_Mongoid - Fatal编程技术网

Ruby 我如何处理Sinatra中的Mongoid错误?

Ruby 我如何处理Sinatra中的Mongoid错误?,ruby,sinatra,mongoid,Ruby,Sinatra,Mongoid,可以在我的Sinatra应用程序中编写一个错误处理程序来处理来自Mongoid的错误吗?例如,我可以编写一个方法来处理来自Mongoid的DocumentNotFound异常吗?当然可以 在Sinatra中为Mongoid异常编写错误处理程序: error Mongoid::Errors::DocumentNotFound do #pass the id's to the view haml :mongoiderror, :locals => { :ids => reques

可以在我的Sinatra应用程序中编写一个错误处理程序来处理来自Mongoid的错误吗?例如,我可以编写一个方法来处理来自Mongoid的DocumentNotFound异常吗?

当然可以

在Sinatra中为Mongoid异常编写错误处理程序:

error Mongoid::Errors::DocumentNotFound do
  #pass the id's to the view
  haml :mongoiderror, :locals => { :ids => request.env['sinatra.error'].identifiers }
end