I have three models: Users
, Songs
, Ratings
. A user
has songs
which other users leave ratings
on. I want to create an ordered list that has the users with the highest ratings at the top.
I am able to show the average ratings received by adding this to the user
model:
has_many :ratingsReceived, :through => :songs, :source => :ratings
and then in the view:
<%= user.ratingsReceived.average(:overall) %>
I just can't figure out how to make an ordered list out of this.
Any help is appreciated.
Here's how my models have the associations set up:
class Rating < ActiveRecord::Base
belongs_to :song
belongs_to :user
class User < ActiveRecord::Base
has_many :songs, dependent: :destroy
has_many :ratings
has_many :ratingsReceived, :through => :songs, :source => :ratings
class Track < ActiveRecord::Base
belongs_to :user
has_many :ratings, dependent: :destroy