Rails - take (4), but the bottom is not the top?

I have @comments that lets you speak 17 posts

What I want is the last 4: 14,15,16,17

I tried:

<% @comments.take(4).each do |comment| %> 

But this returns the first 4 .. How can I take the last 4 comments, not the first 4

thanks

+4
source share
2 answers

You can also do:

 @comments.last(4)... 
+13
source
 <% @comments.reverse.take(4).each do |comment| %> 
+5
source

Source: https://habr.com/ru/post/1333319/


All Articles