As Sinatra, Padrino route definitions accept regex when used as the :map option’s value in named aliases.
A standard named alias (‘thisroute’) mapped to some url with a code parameter embedded in the URL:
# For URLs like /someslug/anytext get :thisroute, :map => '/someslug/:code' do # code param available as params[:code] end
Accessing it as a block parameter, like in Sinatra, is also possible:
# For URLs like /someslug/anytext get :thisroute, :map => '/someslug/:code' do |code| # code param available as request scope variable named code end
And the killer one, if we want to enforce a pattern to the parameter, we capture it in a regex (suppose we only want to allow digits for that parameter, one or more), like this:
# For URLs with digits in param., only e.g. /someslug/123 get :thisroute, :map => %r|/someslug/([\d]+)| do |code| # code made of digits captured by regex available as code var. end
Behold! And YES!! The first capture (text matched by the regex portion inside the parenthesis – the regex syntax element which delimits a capturing group) is available as the first block parameter, super conviniently! Now go enjoy it, and boost up your Padrino application routing!