开发者

Select everything in a database WHERE & order by

开发者 https://www.devze.com 2023-03-31 19:41 出处:网络
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

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

精彩评论

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