A widget has_one type, and type has_many widgets. I'd like to count which types are the most commonly assigned to my widgets (top 3 used).
What would be the best way to accomplish this?
The way I have the database structured is the widgets table has a type_id, which is assigned by a select when creating the widget.
I imagined that this would be a method I'd define in the model of my widget.rb, since I'd need to collect all my widgets before counting up the types and giving them a "score" if you will.
I'm wondering if there is an easier way to figure out which of the types are most used - my goal is to return them from the method in the model, which is created as an array and assigned to a variable in the controller.
The view them pulls the top three by simply calling first three values of the array.