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.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
578 Understanding How to Configure Google API Key
581 PHP ssh2_scp_send fails to send files as intended
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.