Reputation: 2899
How can I sort a MySQL table and display it in HTML using sort_by in Ruby (by values "views")?
My display code is:
<html>
....
..
<% @f_videos.each do |f_video| %>
<display code .......>
...
..
</html>
will this work?
f_videos.replace f_videos.sort_by {views}
?
Upvotes: 0
Views: 72
Reputation: 37141
It's not very clear what the structure of your data is, but if possible, you should just use the order
method when looking up objects rather than using sort_by
.
@f_videos = Video.order(:views)
Upvotes: 5