How to use params with slashes with Sinatra?

后端 未结 3 887
执笔经年
执笔经年 2020-12-11 03:40

Playing with sinatra, I\'m stuck on a little problem : when I use params with slashes, it confuses the router engine. So is there a nice way to handle this kind of param wit

相关标签:
3条回答
  • 2020-12-11 04:21

    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
    
    0 讨论(0)
  • 2020-12-11 04:31

    or use:

    url = request.fullpath[5..-1]
    
    0 讨论(0)
  • 2020-12-11 04:34

    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
    
    0 讨论(0)
提交回复
热议问题