开发者

Select everything in a database WHERE & order by

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜