我有一个User
和Shop
模型。关系是:User has_many :shops
。
User
模型中有一个范围:
scope :order_by, ->(order_by) { order("#{order_by} DESC") }
如何按shops
计数对用户进行排序?
像
<%= select_tag(:order_by, options_for_select([["Name", "name"], ["E-mail", "email"],
["Shops count", "user.shops.count"],
["Date of creation", "created_at"]],
"Date of creation")) %>