Sha256: d5a93878c6e79619449aa144789cc62c5d14d2fbcef7ea466ec64b2a90c64889
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'rails_admin/config/fields' require 'rails_admin/config/fields/types' require 'rails_admin/config/fields/types/file_upload' # Register a custom field factory RailsAdmin::Config::Fields.register_factory do |parent, properties, fields| paperclip_columns = [:file_name, :content_type, :file_size, :updated_at] model = parent.abstract_model.model if defined?(::Paperclip) and model.kind_of?(Paperclip::ClassMethods) if part = paperclip_columns.detect {|it| properties[:name].to_s.strip =~ /^(.+)_#{it}$/ } attachment_name = properties[:name].to_s.scan(/^(.+)_#{part}$/).first.first.to_sym if model.attachment_definitions && model.attachment_definitions.has_key?(attachment_name) && fields.find{|f| attachment_name == f.name}.nil? paperclip_columns.each do |it| if props = parent.abstract_model.properties.find {|p| "#{attachment_name}_#{it}" == p[:name].to_s } RailsAdmin::Config::Fields.default_factory.call(parent, props, fields) fields.last.hide end end fields << RailsAdmin::Config::Fields::Types::Paperclip.new(parent, attachment_name, properties) true end end else false end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
elucid-rails_admin-0.0.1 | lib/rails_admin/config/fields/factories/paperclip.rb |