Replies: 4 comments 2 replies
-
Hi @milouse - I've based my own apps off of Jeremy's roda-sequel skeleton here (https://github.com/jeremyevans/roda-sequel-stack). You can see the route splitting here (https://github.com/jeremyevans/roda-sequel-stack/blob/master/app.rb#L77-L87) and the route itself here (https://github.com/jeremyevans/roda-sequel-stack/blob/master/routes/prefix1.rb)
|
Beta Was this translation helpful? Give feedback.
-
@kez I would definitely recommend the hash_routes approach. roda-sequel-stack is a good starting point if you want much of the setup taken care of for you. You can always just look at it and get ideas from it as opposed to cloning it if that suits your needs better. Note that your example with |
Beta Was this translation helpful? Give feedback.
-
Oh, thank you both of you for your answer. It seems I was too tired yesterday evening, because I found this template project, but missed the route declaration 🤦 I’m glad to have found by myself that it was a matter of re-opening the app class. I’m not sure I need to depend on rack-unreloader, and in any case, to be sure I correctly understand all of that: Unreloader is just a wrapper around |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I’m very sorry as the answer of this question surely involved more basic ruby knowledge than something specific to roda. However It’s only in the case of the development of a little web app with roda that I really struggle to understand how I can split my code to gain in readability.
I would like to avoid to have the whole world in a single ruby file. As my little web app involves a database, I’ve already been able to move all models related code in a model subfolder. My next step would be to split up the routing tree into several parts.
My first attempt was to embed the separated tree parts into different functions stored in different files. Before declaring my app, I required all that files, then I used a specific method to call that function when needed:
routes/feature1.rb
routes/feature2.rb
app.rb
But I was afraid it was no very efficient, nor following any convention of roda. Thus I look for an already existing plugin and found the hash_route one, which seems to be the right things to use.
Thus I rewrite my code to look like the following:
routes/feature1.rb
routes/feature2.rb
app.rb
However obviously I get a crash has the
hash_path
method is not defined in the various routes files. Thus I wonder how I should write this route files? Should I reopen my App class?And in that case, it means I must require my route files after the declaration of my App?
Or is there another way to do it I just don’t know?
Thank you very much for your advices.
Beta Was this translation helpful? Give feedback.
All reactions