From 49ec846c38fdfabf6f39cc2ed83504cbf736dd85 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 8 Dec 2015 19:08:29 +0800 Subject: [PATCH] sort fix --- app/models/experience.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/experience.rb b/app/models/experience.rb index 0066fd9..ed5df74 100644 --- a/app/models/experience.rb +++ b/app/models/experience.rb @@ -54,7 +54,7 @@ class Experience "plugin_data_title" => I18n.t("personal_experience.#{t}") } end - plugin_datas = datas.sort_for_frontend.collect do |p| + plugin_datas = datas.sort_for_frontend.collect.with_index do |p,index| pd_data = [] fields_to_show.collect do |t| @@ -77,11 +77,12 @@ class Experience { "pd_datas" => pd_data, - "type-sort" => (p.experience_type.sort_position rescue 1000) + "type-sort" => (p.experience_type.sort_position rescue 1000), + "sort-index" => index.to_s } end - plugin_datas = plugin_datas.sort{|k,v| k["type-sort"] <=> v["type-sort"]} + plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]} return [pd_title,plugin_datas] end