What do you want to do
In my own application, I use the following each statement to display posts, but I would like to limit the display limit to 10.
At that time, I would like to make the specification disappear from the old one.
<%@notifications.each do | notification|%>
<div class="notifications-index-item">
<%case notification.action%>
<%when "post"%>
<%=link_to(notification.post.dear, "/posts/#{notification.post.id}")%>br>
<%when "reply"%>
<%=link_to(notification.reply.dear, "/replies/#{notification.reply.id}")%>br>
<%else%>
<p> Not yet here</p>
<%end%>
</div>
<%end%>
If things go on as they are now, the posts will probably be displayed indefinitely, so please let me know.
ruby-on-rails ruby
@notifications
depends on the nanny:
@notifications.sort_by.reverse.take(10).each do...
Array#take
.sort_by{...}.reverse
instead of sort{|a,b|b.date and time items <=>a.date and time items}
.order (date and time attribute you want to sort::desc).limit(10)
to the query.
© 2024 OneMinuteCode. All rights reserved.