How do I get this custom array?
I want the first four notifications that are unread notifications.where(:read => false)[0,4].map
. However, if there are fewer than four notifications that are unread, I want the rest of the four notifications to be fil开发者_如何学Cled up by read ones. How do I do this?
(Also, the .where(:read => false)
doesn't seem to work.)
Try:
(notifications.where(:read => false).limit(4) + notifications.where(:read => true).limit(4))[0,4]
You can also try
notifications.order(:read).limit(4)
Which should give you falses first then trues.
精彩评论