Sha256: 9035920a31375985286c3a511e626db74faac37589ed91a865f9a1230fe07e16

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

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|
  extensions = [:name, :uid]
  if (properties.name.to_s =~ /^(.+)_uid$/) && defined?(::Dragonfly) && parent.abstract_model.model.dragonfly_attachment_classes.collect(&:attribute).include?(attachment_name = Regexp.last_match[1].to_sym)
    field = RailsAdmin::Config::Fields::Types.load(:dragonfly).new(parent, attachment_name, properties)
    children_fields = []
    extensions.each do |ext|
      children_column_name = "#{attachment_name}_#{ext}".to_sym
      next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
      children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
      children_field.hide
      children_field.filterable(false)
      children_fields << children_field.name
    end
    field.children_fields(children_fields)
    fields << field
    true
  else
    false
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
rails_admin-1.4.3 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.3.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.2.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.1.1 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.1.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.0.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-1.0.0.rc lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.8.1 lib/rails_admin/config/fields/factories/dragonfly.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rails_admin-0.7.0/lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.7.0 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.8 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.7 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.6 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.5 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.4 lib/rails_admin/config/fields/factories/dragonfly.rb
rails_admin-0.6.3 lib/rails_admin/config/fields/factories/dragonfly.rb