From 605b45d10de8ba6a923626b427baec8c7d501c3a Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 15 Feb 2016 18:30:38 +0800 Subject: [PATCH] remove empty columns --- app/models/writing_conference.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/writing_conference.rb b/app/models/writing_conference.rb index 6eeffde..bfbf21b 100644 --- a/app/models/writing_conference.rb +++ b/app/models/writing_conference.rb @@ -71,12 +71,23 @@ class WritingConference "paper_title" ] - pd_title = fields_to_show.collect do |t| - { - "plugin_data_title" => I18n.t("personal_conference.#{t}") - } + fields_to_remove = [] + + pd_title = [] + + fields_to_show.each do |t| + if (self.fields[t].type.to_s == "String" rescue false) + fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false) + else + fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) + end + pd_title << { + "plugin_data_title" => I18n.t("personal_conference.#{t}") + } if !fields_to_remove.include?(t) end + fields_to_show = fields_to_show - fields_to_remove + plugin_datas = datas.sort_for_frontend.collect do |p| pd_data = []