> Thanks for the reply Eleo - you've given me some food for thought.
>
> I will keep bumping this up in hopes that one of the code devs will chime in.
Yep, keep bumping this. I hope that I finally find the time to write my perspective
on my train ride home today.
My opinion on this is: The word "controller" is a lie and should be replaced by "namespace", because thats what padrino controllers actually are: fancy definition blocks that have some context, but ultimately compile down to routes. As such, they don't really merit the "class approach". If you need a class behind your routes, implement one. Padrino doesn't really have 'controllers'. The trap here is that people treat Padrino applications like Rails applications: there is only one app directory, sometimes there are two (app and admin). What you end up is a huge number of files in app/controllers, a lot of special casing in app.rb and quite a few helpers with specialized functionality in app/helpers and a bunch of models with no inner order in models. Yet, they miss the crucial part: Padrino is perfectly capable to mount multiple applications together and let them act as one. So the method of separation is "multiple apps", not "multiple controllers".
What you should do, is the following:
* Everything that has widely divergent use-cases, naming schemes or models should land in its own app (e.g. Frontend, Api, Admin, Dashboard, UploadLocation). If you do this right, you can develop with only one app directory open at all times. Use the fact that all applications can have different settings. Applications can depend on others, but only in one direction. If applications show a cyclic dependency, move them back into one.
* If 2 apps share helpers or code, implement them as Sinatra plugins and put them in "lib" instead. This ensures that code is never loaded twice. Register them in app.rb anywhere you please. The initalizers that Padrino generates (SassInitializer etc.) are a good example of how small they can be. Make this a habit.
- Read about Sinatra::Application.helpers and Sinatra::Application.register
* Shared models always go to /models
* Try to break out of your controller code as fast as possible and delegate to a library (thats actually true for Rails as well). This is similar to GUI programming: you usually don't implement what a click does in the click handler. Everything concerned to produce a HTTP response (status, redirect, etc.) does belong in the app though.
* If you are tired of having a huge "register" block on top of all your app.rb files, build your own application class on top of Padrino::Application.
* Learn about Rack, Sinatra::Application.use and Padrino.use. They allow fine-grained control of the middleware-stack and are key to doing most of the stuff you would do in before-filter instead. Having multiple applications allows you to differ on the Rack middleware stack without playing with to many conditionals.
Okay, end of the train ride, please ask any questions that come up.
Regards,
Florian