Reputation: 2333
I want to sort array from controller, that doesn't works, but throws no errors.
def my_published
@tests=Test.where(:user_id => current_user.id, :state=>'saved')
@[email protected] { |p1, p2| p1.rating <=> p2.rating }
respond_to do |format|
format.html
format.js{@tests}
end
end
Rating is an integer. P.S. To display array I use each method.
Upvotes: 0
Views: 36
Reputation: 21791
Try this construction:
@test = Test.where(:user_id=>current_user.id, :state=>'saved').order('rating')
You can add the direction of order:
order('rating DESC') or order('rating ASC')
Upvotes: 1