开发者

Override default route if no parameter specified

开发者 https://www.devze.com 2022-12-25 05:47 出处:网络
Consider the following snippet: get \'/hello/:name\' do |n| \"Hello #{n}!\" end How can I set a default parameters if name isn\'t specified? If I can set the def开发者_如何学Pythonault paramater to

Consider the following snippet:

  get '/hello/:name' do |n|
        "Hello #{n}!"
  end

How can I set a default parameters if name isn't specified? If I can set the def开发者_如何学Pythonault paramater to Tom will this also route the URL so /hello/ will automatically redirect to /hello/tom?


I think you have to do something like:

get '/hello/' do
  redirect '/hello/tom'
end

You could do 'hello/*' and access it through params[:splat], if you just want one place for the logic. But you would still have to redirect to get to the /hello/tom url from /hello/.

0

精彩评论

暂无评论...
验证码 换一张
取 消