Reputation: 5813
I'm working on a Rails application that will spit out a series of measurements that are taken over a period of days. Each measurement is stored as an individual record with a datetime and a value (plus other metadata)
When I query the data (using a specific date range) , I basically want the values grouped by DAY, so going from something like this:
datetime, value
datetime, value
datetime, value
datetime, value
datetime, value
datetime, value
to something like this:
date:
time, value
time, value
time, value
date:
time, value
time, value
time, value
I would return the data as JSON.
Now, my question is fairly high-level:
What is the best place in the application to make this transformation? Should I create a method in the model that returns data on this format? Should this be part of my controller action? Or should I do this on a jbuilder template?
I'd like to know what is considered the best practice, and why.
Thanks!
Upvotes: 0
Views: 130
Reputation: 348
If we're dealing with data of a table of model, we should put the method in its own model. However, in order to make your model short, I recommend you create a module with single responsibility. Then including this module in corresponding model. Locating this module in models/concerns. Hope it's useful.
Upvotes: 2