Basic Rails 3 question: How to sort products?

这一生的挚爱 提交于 2019-12-03 08:59:58

Austin L is right, but his syntax is a bit old. The new ActiveRecord syntax is much cleaner:

@products = Product.includes(:shop, :brand).order("shops.name ASC, brands.name ASC")
Austin Lin

See this article: http://www.definenull.com/node/8

In your example:

@products = Product.find(:all,:include => [:shop, :brand], :order => 'shops.name ASC, brands.name ASC')

I haven't tested this code myself so I can't vouch for it 100% but give it a try. If it dosent work try removing the "ASC" and see if that runs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!