I would like to have a Dashboard page that gather information from multiple models to a summary view (without its own model). How should I go about it the Rails way? Should I create a dashboard_controller with just index action?
Thank you.
just think a little less Rails. i'm assuming your dashboard contains mainly widgets? i.e. some self contained elements, whatever? why not make those widgets your model (not AR-based). encapsulate all your logic and data retrieval in your widget model(s). so now if you want to go RESTful, you could for example make a WidgetsController
with an index
action as dashboard. in a second step you could use your show action to provide JSON data for each widget for AJAX parts of your dashboard. etc.
just remember REST is not necessarily == CRUD, and a Model doesn't need to be a ActiveRecord model. Rails forces you into the MVC pattern, which is a great thing, and makes even poorly written Rails apps better than a lot of PHP mayhem out there, but sometimes we tend to forget that there are a lot of possibilities outside of ActionController + ActiveRecord etc.
What you would want is to take a look at the administration frameworks and see if that solves your needs, I like Typus and RailsAdmin Otherwise you would want to take a look at the presenter pattern and how it applies to Rails and your application. A dashboard basically would only interface with your existing models and controller logic since you dont want to end up with a situation where you have two sets of logic for each model. While the blog I linked to is from 2007 you should be able to pull some useful information off of it and get the idea of what you need to do.
If you have any questions feel free to ask.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With