Ruby on Rails范围计算数据

时间:2014-08-20 15:45:41

标签: ruby-on-rails sorting scope calculated-field

我有一个UserShop模型。关系是: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")) %>

0 个答案:

没有答案