wildcard path

7 views
Skip to first unread message

yad...@gmail.com

unread,
Apr 21, 2008, 10:20:00 AM4/21/08
to sinatrarb

Hi,

sinatra is great
(i'm new to ruby, and it's great too :))

quick question ?

get '/message/*' do
# matches /message/1/2/3/4/5
end

how do i get the matched part, i.e. 1/2/3/4/5

??
thanks,

Roger

Dev Purkayastha

unread,
Apr 21, 2008, 11:17:52 AM4/21/08
to sinatrarb
I do believe that it's get '/message/:foobar', and you get the
contents of that matched piece in params[:foobar].

-d

yad...@gmail.com

unread,
Apr 21, 2008, 12:27:59 PM4/21/08
to sinatrarb

Hi,

As far as I can tell, if i

have

get '/message/:foobar'

it will match
/message/a
but not
/message/a/b/c

(?)
thanks,

Roger

On Apr 21, 5:17 pm, Dev Purkayastha <dev.purkayas...@gmail.com>
wrote:

Blake Mizerany

unread,
Apr 21, 2008, 2:51:35 PM4/21/08
to sina...@googlegroups.com
This has become a real feature request.  I'm getting asked this alot.   mapar has mentioned he has a fix and will send a patch.  for now you simply:

get '/foo/*' do
  splat = request.path_info.split('/')[1..-1].join('/') # or use gsub to replace the prefix with a blank string
  ... use splat for something ...
end
--
Blake Mizerany
blake.m...@gmail.com
Reply all
Reply to author
Forward
0 new messages