Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data of last 24 hours on top in rails

There is a model post . Post are created by either PM or User. I want to get all posts in which the posts created by PM in last 24 hours come on top.

I try

posts.sort_by{|t| -t["role_id"] }

But by this PM all posts on top. I want PM posts of only last 24 hours on top.

like image 304
Haseeb Ahmad Avatar asked Dec 10 '25 19:12

Haseeb Ahmad


1 Answers

Try this: Post.where('created_at > ?', 24.hours.ago).order(role_id: :asc)

like image 79
Murad Yusufov Avatar answered Dec 12 '25 07:12

Murad Yusufov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!