Kevin Vanzandberghe

Joined

2,400 Experience
17 Lessons Completed
1 Question Solved

Activity

Posted in Best Method For User's Dashboard?

Hi Rich, 

When I do dashboards, I generally create a singular route, e.g. `resource :dashboard, only: :show`.

That way, you can have a singular controller name. To organize the data that will be displayed, either create a `Dashboard` model as a plain ruby object, or a `DashboardPresenter`. You can expose that object in your view with `helper_method`.

Your instinct to create a dedicated controller was the right one imo. As far as the end-user is concerned, a dashboard is a resource, even if in technical terms, is it just an aggregate of other data. 

> I considered simply adding businesses#dashboard, but that seems wrong.

Same feeling. When I'm tempted to create a non-REST method in a controller, I often realize that's the smell for the need of a discrete resource.

Hope that helps!
logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.