It seems that in Sinatra all route handlers are being written into a single file, if I understand right it acts as a one large/small controller. Is there any way to split it into separate independent files, so when let’s say somebody calls "/" – one action is executed, and if something like "/posts/2" is received then another action – similar logic that is applied in PHP?
Share
Here is a basic template for Sinatra apps that I use. (My larger apps have 200+ files broken out like this, not counting vendor’d gems, covering 75-100 explicit routes. Some of these routes are Regexp routes covering an additional 50+ route patterns.) When using Thin, you run an app like this using:
thin -R config.ru startEdit: I’m now maintaining my own Monk skeleton based on the below called Riblits. To use it to copy my template as the basis for your own projects:
File Layout:
config.ru
app.rb
helpers/init.rb
helpers/partials.rb
helpers/nicebytes.rb
models/init.rb
models/user.rb
routes/init.rb
routes/login.rb
routes/main.rb
views/layout.haml