How can I order my records by amount from a separate table?
I am wondering how I can order the posts in my PostController # index to be displayed by full column in a separate table. This is how I set it up.
class Post < ActiveRecord::Base
:has_many :votes
end
and
Class Vote < ActiveRecord::Base
:belongs_to :post
end
The user can either vote up or down on a particular entry. I know there are probably better ways to do what I am doing now, but look for a fix given the current situation. When a user votes for a message, the value 1 is passed to the voting table through a hidden field. When a user votes on a post, a value of -1 is passed to the same column (votes are being voted).
I am wondering how I can display my posts in the order of the sum of the voting column (in the vote table) for a specific position.
Another way of saying is that if a particular post has a net total of 5 votes, I want this to appear above the post with a total vote of 4.
I am guessing that I need to somehow influence the PostController # index action. But not sure how to do it.
a source to share