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 without having to encode it ?
The code looks like
get 'add/:url' do
#....
end
And I intend to get something like /add/http://sctackoverflow.com/ working
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]
来源:https://stackoverflow.com/questions/529065/how-to-use-params-with-slashes-with-sinatra