Skip to main content

Best Method For User's Dashboard?

Rails • Asked by Rich Smith
Hi, I am looking for advice on the best way to organize a dashboard to show the user various information from across different models. 

I was considering just generating a DasboardsController, but that doesn't seem very rails-y - for starts because of the fact that it is plural when in reality, it just needs to be DashboardController#index.


My app is set up in the following way:

Users
    |
    Businesses
        |
        Locations
         |  |
         |  Requests
        Payments
        OtherThings

I considered simply adding businesses#dashboard, but that seems wrong. I am trying to display chunks of info from children of the business model.

Any suggestions on design pattern here?

Cheers!

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!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.