0

I am trying to do some tricks with routes. And I need to use optional route parameter in Padrino. I googled that solution for this are "()" parenthesis. I couldn't find in docs.

But when I try to use

get :sort, :with => [:order, :asc, '(:search)'] do

them, mustermann is giving me classic error for missing parameter

cannot expand with keys [:asc, :order], possible expansions: [:asc, :order, :search]

when I try to call

url(:sbirka, :sort, :order => "id", :asc => @asc)

I also tried different style

get :sort, "/:order/:asc/(:search)" do

with the same result

Please any suggestions how to do this?

Mlok
  • 155
  • 9

1 Answers1

0

Since Padrino is based on Sinatra, every routing pattern possible with Sinatra should be possible in Padrino as well. From Sinatra's excellent README file, introductory 'Routes' section:

Route patterns may have optional parameters

In your case, assuming :search is optional, I would try:

get '/:order/:asc/:search?' do
  # your  code
end
Bartosz Pietraszko
  • 1,367
  • 9
  • 9
  • Thanks so much! I will try, it is working like route, I must change my url helpers for sinatra style, padrino style url(:sbirka, :sort, :order => "country", :asc => @asc) does not work, I will write as soon as I will try – Mlok Apr 10 '18 at 11:56
  • It is not working :( If I use :search? as in example, I get 404 not found, when I put :search? away, it is working. – Mlok Apr 10 '18 at 17:41