From a245f3ebbfc12ecbb25945319cf9204dd2def7a6 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 3 Feb 2017 17:17:08 +0000 Subject: [PATCH] Fix custom attributes exporting on content --- app/controllers/export_controller.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 4221909e..8d0ac577 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -84,7 +84,12 @@ class ExportController < ApplicationController ar_relation.each do |content| csv << attribute_categories.flat_map(&:attribute_fields).map do |attr| - value = content.send(attr.name) + begin + value = content.send(attr.name) + rescue + value = Attribute.where(user: current_user, attribute_field: attr, entity: content).first + value = value.value if value + end if value.is_a?(ActiveRecord::Associations::CollectionProxy) value = value.map(&:name).to_sentence @@ -107,7 +112,12 @@ class ExportController < ApplicationController content_repr = {} attribute_categories.flat_map(&:attribute_fields).each do |attr| - value = content.send(attr.name) + begin + value = content.send(attr.name) + rescue + value = Attribute.where(user: current_user, attribute_field: attr, entity: content).first + value = value.value if value + end next if value.nil? || value.blank? if value.is_a?(ActiveRecord::Associations::CollectionProxy) @@ -137,7 +147,12 @@ class ExportController < ApplicationController text << " #{content.name}\n" attribute_categories.flat_map(&:attribute_fields).each do |attr| - value = content.send(attr.name) + begin + value = content.send(attr.name) + rescue + value = Attribute.where(user: current_user, attribute_field: attr, entity: content).first + value = value.value if value + end next if value.nil? || value.blank? || (value.respond_to?(:empty) && value.empty?) if value.is_a?(ActiveRecord::Associations::CollectionProxy)