Sha256: d88f9d2501f9b79d066ef179e3080082617bd1306e75923f01f265a8e18547d1

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 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|
  model = parent.abstract_model.model
  if defined?(::CarrierWave) && model.is_a?(CarrierWave::Mount) && model.uploaders.include?(attachment_name = properties.name.to_s.chomp('_file_name').to_sym)
    columns = [model.uploader_options[attachment_name][:mount_on] || attachment_name, "#{attachment_name}_content_type".to_sym, "#{attachment_name}_file_size".to_sym]
    field = RailsAdmin::Config::Fields::Types.load(
      [:serialized, :json].include?(properties.type) ? :multiple_carrierwave : :carrierwave,
    ).new(parent, attachment_name, properties)
    fields << field
    children_fields = []
    columns.each do |children_column_name|
      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 unless field == children_field
      children_field.filterable(false) unless field == children_field
      children_fields << children_field.name
    end
    field.children_fields(children_fields)
    true
  else
    false
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.3.0 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.2.1 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.2.0 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.1.1 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.1.0 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.0.2 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-1.4.3 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.0.1 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.0.0 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.0.0.rc lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-2.0.0.beta lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/factories/carrierwave.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/factories/carrierwave.rb