如何在 Sinatra 中共享错误和 not_found 处理程序
我正在使用 Ruby 和 Sinatra 创建一个 Web 应用程序,并将各个方面拆分为单独的 Sinatra::Base
类,如下所示:
class Frontend < Sinatra::Base
get '/' do
erb :home
end
end
class Backend < Sinatra::Base
get '/account' do
erb :account
end
end
现在我想使用 not_found 和
error
路由,但我不想在两个类中重复它们。
声明一次并将它们应用于两个类中的路由的最佳方法是什么?
I am creating a web app using Ruby and Sinatra, and I'm splitting up the various aspects into separate Sinatra::Base
classes, like so:
class Frontend < Sinatra::Base
get '/' do
erb :home
end
end
class Backend < Sinatra::Base
get '/account' do
erb :account
end
end
Now I want to use the not_found
and error
routes, but I don't want to duplicate them in both classes.
What's the best way to declare them once and have them apply to routes in both classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)