How would you present customer data using a dashboard?

I need to build a crm-like dashboard to present customer data to the logged in user.
Would you implement the dashboard as property of the customer using something like

schema "customers" do
  has_one(:dashboard, Dashboard )

Or would you just have a Dashboard controller (not a table) and only make it available on certain routes?
For example let’s say the logged in user is viewing the customer show page. I could then get customer from the params and look
them up in the database then present the customer data on the dashboard.

Both ways would work but which is less error prone? Or is there another way to do this that I’m not seeing?

Hi, @_russellb, I think it would be considered best practices to go the controller route. Phoenix promotes MVC( Model, View, Controller ) principles designed just for this. If I were you I would create a controller for your dashboard, along with that I would create a dashboard template in yourAppWeb/templates/dashboard/index.html.eex and a dashboard view in yourAppWeb/views/ dashboard_view.ex. You can call functions to load your data in your controller and pass that data to your template, in your template you can render the data in your CRM like fashion. You can use your view file to call functions for any logic needed in your template.

Inside your router you can create a route for this page, you can also restrict the route to only allowing certain usesr to view it.


Thanks, that’s the way I’ve been writing this feature. I just wanted some extra opinions on how to do it.