How to use params with slashes with Sinatra?

六月ゝ 毕业季﹏ 提交于 2019-11-28 12:12:47

Did you try to use splat parameters?

Something like:

get '/add/*' do
  protocol = params[:splat].first
  address = params[:splat][1..-1].join('/')

  url = protocol + "//" + address
end

thank you, I haven't heard about splat parameters and it works perfectly for this case. Indeed, I've looked into the documentation and I found even shorter using capture parameters and regular expressions :

get %r{/add/(.+)} do
  url = params[:captures]
end

or use:

url = request.fullpath[5..-1]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!