开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜