Sha256: 8f7e26e4baa01439be91a55b4c9f128ae68c7019b2147025fbb9dd09a9c6edb1

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 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 = [:file_name, :content_type, :file_size, :updated_at]
  model = parent.abstract_model.model
  if (properties[:name].to_s =~ /^(.+)_file_name$/) and defined?(::Paperclip) and model.attachment_definitions and model.attachment_definitions.has_key?(attachment_name = $1.to_sym)
    field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
    children_fields = []
    extensions.each do |ext|
      children_column_name = "#{attachment_name}_#{ext}".to_sym
      if child_properties = parent.abstract_model.properties.find {|p| p[:name].to_s == children_column_name.to_s }
        children_field = fields.find{ |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
    end
    field.children_fields(children_fields)
    fields << field
    true
  else
    false
  end
end

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
rails_admin-0.5.0 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.9 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.8 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.7 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.6 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.5 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.4 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-lbgraham-0.4.2 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.3 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.2 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.1 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.4.0 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.3.0 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.2.0 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.1.2 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.1.1 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.1.0 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.0.5 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.0.4 lib/rails_admin/config/fields/factories/paperclip.rb
rails_admin-0.0.3 lib/rails_admin/config/fields/factories/paperclip.rb