I'm doing the following query...
Status.where(:status => params[:cat_id])
but I want to order the results by the created_at column. I've tried everything logical like
Status.wher开发者_JS百科e(:status => params[:cat_id]), :order => "created_at DESC"
and
Status.where(:status => params[:cat_id], :order => "created_at DESC")
but nothing seems to work.
What's the best way to order results that you're getting from a where query?
Any help is much appreciated, thanks!
Status.where(:status => params[:cat_id]).order("created_at DESC")
You might want to give a look at the ActiveRecord API documentation.
You can do using symbol:
.order(created_at: :DESC)
精彩评论