开发者

How do I get this custom array?

开发者 https://www.devze.com 2023-03-04 04:07 出处:网络
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 no

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消