Test Test
Test Test

Reputation: 2899

Use sort_by in Ruby

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

Answers (1)

Jimmy
Jimmy

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

Related Questions