From d87942c57c62f7ab52bc84cc265eb411f172c332 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 13 Jan 2016 18:44:28 +0800 Subject: [PATCH] field object type check --- app/models/diploma.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/models/diploma.rb b/app/models/diploma.rb index 5a92afa..d5d84b7 100644 --- a/app/models/diploma.rb +++ b/app/models/diploma.rb @@ -49,11 +49,22 @@ class Diploma "duration" ] - pd_title = fields_to_show.collect do |t| - { - "plugin_data_title" => I18n.t("personal_diploma.#{t}") - } - end + fields_to_remove = [] + + pd_title = [] + + fields_to_show.each do |t| + if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" 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_diploma.#{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|