Mimic c# routes in sinatra

23 views
Skip to first unread message

Daniel Penaloza

unread,
Mar 13, 2018, 7:52:21 PM3/13/18
to sinatrarb
Hi guys, there is a way to mimic a c# route like this one:

public ActionResult GetQuestions(int StatusIDView = 0, int ID = 0, int QuestionID = 0) {
 
.....................
}


in Sinatra?, i'm really newbie on sinatra and i'm trying to replicate this kind of sutff, thanks !!

Regards.
Daniel Penaloza.

Jason Rogers

unread,
Mar 13, 2018, 10:10:26 PM3/13/18
to sina...@googlegroups.com
There are several ways to do this. Here are two.

Default route parameters as block parameters:

get '/questions/:view/:id/:question_id' do |view=0, id=0, question_id=0|
  # ...
end

Default parameters within the route:

get '/questions/:view/:id/:question_id' do
  view = parameters.fetch :view, 0
  id = parameters.fetch :id, 0
  question = parameters.fetch :question, 0
  # ...
end



--
Jason Rogers

--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Penaloza

unread,
Mar 14, 2018, 3:30:06 PM3/14/18
to sinatrarb
Hi Jason, many thanks for the information you save my life :) !!

Regards.

Daniel Penaloza.\
Reply all
Reply to author
Forward
0 new messages