Domanda

I am trying to order my posts based on the created date ( newest to oldest ) so i do this :

@posts = Post.order('created_at DESC')

But the posts are not being affected by this. What can the problem be ?

È stato utile?

Soluzione

Try something like this

@posts = Post.order(:created_at)

This way you order your data according to the created_at property

and if you want reversed order then

@posts = Post.order(:created_at).reverse
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top