tags:

views:

33

answers:

1

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 default paramater to Tom will this also route the URL so /hello/ will automatically redirect to /hello/tom?

+1  A: 

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/.

ba
So if I add that block, /hello/blah will still route ok?
Tom
yeah, they are distinct "end paths" as seen by the router :)
ba