Padrino multilpe url for one route code

74 Views Asked by At

I would like to handle multiple URLs with one route code.

I am trying something like this:

get '/company', '/about' do 
  ...
end

but it does not work. For /company, I get 200, but for /about, I get 404.

Is there such way to do this?

1

There are 1 best solutions below

3
Tom Lord On BEST ANSWER

The route file is a ruby file. You can do this with a simple loop:

['/company', '/about'].each do |route|
  get route do
    # ...
  end
end

From the source code:

def get(path, *args, &block)
  conditions = @conditions.dup
  route('GET', path, *args, &block)

  @conditions = conditions
  route('HEAD', path, *args, &block)
end

You can see that the get method only takes a single path.