I'm learning Rails and trying to do this the right way, but I've struggled mightily finding a solution.
I have a long list of sports rankings in my Ranking model that I'm trying to manipulate based on the filters and general business logic applied to it (i.e. date range, sport, etc).
Ranking model
t.string "rank"
t.integer "team_id"
t.integer "sport_id"
t.integer "source_id"
Team model
t.string "team"
t.integer "sport_id"
Sport model
t.string "sport"
One thing I want to do, for example, is find an average of each team's rank over the years. I know one way to do this would be something like Ranking.average(:rank, :group => 'team_id')
, but that doesn't seem very DRY.
Another idea I had was to create an array, hash, json, or even a temporary table (probably not a good idea) to allow me to apply calculations and manipulate the data easier.
Again, I'm still a bit green so I might be missing an easy solution but whats the best practice for this?