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}
?
还不清楚数据的结构是什么,但是如果可能的话,在查找对象时应该只使用order
方法,而不要使用sort_by
。
@f_videos = Video.order(:views)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.