我有一个哈希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_params:{ "page" => 1, "per_page" => 10, "sort" => { "id" => "desc" } }