I use the
Post.order(:created_at)
in the controller and the posts are ordered by create time, but it come out from the oldest to the newest post, that is what i don’t want, I want to change the order to display the recent posts first, how can I change the code?
Use
Post.order("created_at desc")Tip: Use a
scopeso this logic remains on your model, not on your controller.Then, on your controller, you can just use
Post.recent_first.