I'd recommend that you use an AR counter cache here:
4.1.2.4 :counter_cache
The :counter_cache option can be used to make finding the number of belonging objects more efficient.
[...]
Although the :counter_cache option is specified on the model that includes the belongs_to declaration, the actual column must be added to the associated model.
So you'd modify the corresponding belongs_to declarations to include the :counter_cache option:
class Vote < ActiveRecord::Base
belongs_to :post, :counter_cache => true
end
# Similarly for the other two...
and then add counter columns to your posts table in a migration:
def change
change_table :posts do |t|
t.integer :votes_count
#...
end
end
You'll also want a migration to initialize the counters for your existing Posts.
Then you'll have the counters as properties of your models and you can say things like:
Post.where(...).order('posts.votes_count + posts.comments_count + posts.ratings_count')
If you want to include created_at then you could use extract(epoch from created_at) to get the timestamp as a convenient double precision value that you can use in arithmetic expressions.
The downside to this is that the counters can get out of sync if you stray but a hair from The One True Path To Rails Nirvana (or where ever it is really going ;) so you'll need to be careful not to touch the database yourself and always go through the associations to create and destroy things. I'd also recommend that you build a quick'n'dirty sanity checker that you can run every now and then to make sure the counters are correct.
If you're happy to be PostgreSQL-specific then you could ditch the :counter_cache => true nonsense and all the brittleness that comes with it and use triggers in the database to maintain the cached counter values.