0

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 filled up by read ones. How do I do this?

(Also, the .where(:read => false) doesn't seem to work.)

2 Answers 2

1

Try:

(notifications.where(:read => false).limit(4) + notifications.where(:read => true).limit(4))[0,4]
Sign up to request clarification or add additional context in comments.

Comments

1

You can also try

notifications.order(:read).limit(4)

Which should give you falses first then trues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.