I’m looking at statistics on “Cars” & “Trucks.” I have a model for each which tidies up the raw data and returns it in a common format.
Then in the view I have a single “Vehicles” chart which integrates data from the two sources.
Where in my application should this integration happen?
- In the Vehicles controller?
- In some kind of read-only Vehicles model not backed by a database table?
- In lib?
- …?
You can do this in a couple of different ways. You can have a
Vehicleclass which cars and trucks inherit fromCars << VehicleTrucks << VehicleYou can have only a Vehicle table, and have a
VehicleTypecolumn with different types for cars and trucksYou can do it in the controller / view where, if the data is formatted the same, in the controller you can have all the cars and trucks into an
@vehiclevariable that gets passed to a view.If cars and trucks are essentially the same, I would use a VehicleType column in the same table. If you need them to have the same methods, but those methods are implemented differently, I would use a Vehicle base class and have cars and trucks inherit from that.