Sha256: 28245dc45e2cb6f1dc651aad96d79d7a9e58921d6820b5113f9045a9491bea90
Contents?: true
Size: 1.2 KB
Versions: 7
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require 'rails_admin/config/fields' require 'rails_admin/config/fields/types' require 'rails_admin/config/fields/types/file_upload' RailsAdmin::Config::Fields.register_factory do |parent, properties, fields| next false unless defined?(::Shrine) attachment_names = parent.abstract_model.model.ancestors.select { |m| m.is_a?(Shrine::Attachment) }.map { |a| a.instance_variable_get('@name') } next false if attachment_names.blank? attachment_name = attachment_names.detect { |a| a == properties.name.to_s.chomp('_data').to_sym } next false unless attachment_name field = RailsAdmin::Config::Fields::Types.load(:shrine).new(parent, attachment_name, properties) fields << field data_field_name = :"#{attachment_name}_data" child_properties = parent.abstract_model.properties.detect { |p| p.name == data_field_name } next true unless child_properties children_field = fields.detect { |f| f.name == data_field_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields) children_field.hide unless field == children_field children_field.filterable(false) unless field == children_field field.children_fields([data_field_name]) true end
Version data entries
7 entries across 7 versions & 1 rubygems