2

In Padrino, if I want a single route to match the following urls:

  • "/does/not/work/for/some.reason"
  • "/does/not/work/for/some.bizarre.reason"

How would I do that? I.e. the last part of the url can have an arbitrarily number of periods in it, and I want that to be one of the parameters.

I tried doing the following, but the route would not match

  • get '/does/not/work/for/:name' do
  • get '/does/not/work/for/*splat' do

However, if I changed the periods to an underscore like "/does/note/work/for/some_reason" they work fine.

Also, if I do the following:

  • "/does/not/work/for/some.bizarre.reason/info"

then both

  • get '/does/not/work/for/:name/info'
  • get '/does/not/work/for/*splat/info'

match fine...

Am I missing something?

BЈовић
  • 62,405
  • 41
  • 173
  • 273
wciu
  • 1,183
  • 2
  • 9
  • 24
  • Would you mind reformatting your post using the code tag or by putting 4 spaces at the beginning of the code samples? The difference between having a question answered or not can be helped by that. Also, please specify how you know that the route is being matched or not, and whether you are using a block variable with those routes or not i.e. `do |name|` – ian Jan 04 '12 at 05:48
  • Are you using :map => ~ ? It might be trying to interpret it as an extension. How about: "/does/not/work/for/some.reason/" ? – minikomi Jan 04 '12 at 06:08

1 Answers1

0

Using a regexp

# GET /with/regexp/it.will.work
get %r{\A/with/regexp/(.*)\Z} do |name|
  # name => "it.will.work"
end

Using a named parameter

Padrino will try and match a format at the end of the URL like .json or .html

The format is accessible through params[:format], you need to join this with params[:name]

# GET /with/named/param/it.also.works.with.a.format
get :named, :map => '/with/named/param/:name'
  name = "#{params[:name]}.#{params[:format]}"
  # name => "it.also.works.with.a.format"
end
Luke Antins
  • 2,010
  • 1
  • 19
  • 15