Reputation: 2821
BACKGROUND: I have a list of posts that need to be sorted their 'votes' and then show the top 50 posts.
OBJECTIVE: I am currently using .take(50)
to accomplish this, as using .limit(50)
or .first(50)
show the first 50 posts UNSORTED.
Using .take
makes the app unusually slow, are there any alternatives to this method?
Upvotes: 0
Views: 480
Reputation: 1604
You can combine limit and order clauses using something like:
Post.all(:order => "votes", :limit => 50)
This generates SQL that only selected 50 Posts, but ordered.
Upvotes: 3