按特定参数对哈希进行排序-哈希的未定义方法`sort_method'

时间:2019-10-07 05:32:37

标签: ruby-on-rails ruby

我有一个哈希collection,我想按declared_params[:sort]进行排序。所以我写了这样的东西

collection.sort_method(declared_params[:sort])

但是我有一个错误

  

#Hash:0x00007ffaafcab140的未定义方法`sort_method>

我要排序的哈希collection如下:

{
  data: [{
    id: "1",
    type: :credit_campaign,
    attributes: {
      name: "Credit Campaign #1",
      interest_rate: 12,
      start_date: "Fri, 04 Oct 2019",
      end_date: "Mon, 04 Nov 2019",
      total_campaign_codes_amount: 15,
      used_campaign_codes_amount: 0
    }
  }]
}

declared_pa​​rams:{ "page" => 1, "per_page" => 10, "sort" => { "id" => "desc" } }

0 个答案:

没有答案