gpt4 book ai didi

ruby - 获取 Sinatra 请求路由/路径

转载 作者:数据小太阳 更新时间:2023-10-29 08:35:55 24 4
gpt4 key购买 nike

有没有办法在 Sinatra 中获取请求路由。比如我有一条路线:

get "/:id/post" do
# whatever
end

当我到达那个端点时,例如,“/abc/post”,我想记录路由:“/:id/post”,而不是 “/abc/post",我可以通过 request.path_info 获取。

我们将不胜感激。

最佳答案

路由器stores the matched route in @env["sinatra.route"] ,所以你可以这样做:

get '/:id/post' do
logger.info "Route: #{@env["sinatra.route"]}"
# ...
end

这将记录:

I, [2016-12-05T10:59:36.678467 #35615]  INFO -- : Route: GET /:id/post

关于ruby - 获取 Sinatra 请求路由/路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40978705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com