Reputation: 49172
What's the correct way to do routing in a Sinatra view. In Rails we have named routes which are accessible in the controller and view.
Hardcoding the route in the the view feels bad. Is it just a matter of writing custom route helpers, or is there a more standard approach?
Upvotes: 0
Views: 1288
Reputation: 9622
The best way is to set up a view helper function. Since Sinatra does not provide view helpers by default, and there is no helper available in sinatra contrib, there is no standard library, and also searching for url helpers turns out not to be too helpful.
Everything that Sinatra provides is the URL Helper but this is not constructing urls either.
I did find however an outdated gem that is doing what you want. It's just one method to do named routing, maybe this provides you with some inspiration to achieve dynamic route calling.
Upvotes: 2