Sha256: 995c92ef2407c0bd8459a09a7cda93efa309c709845c2b815f63582434c04e6f

Contents?: true

Size: 1.15 KB

Versions: 29

Compression:

Stored size: 1.15 KB

Contents

module ActiveScaffold
  module Bridges
    class Paperclip
      module PaperclipBridge
        def initialize_with_paperclip(model_id)
          initialize_without_paperclip(model_id)
          return unless model.respond_to?(:attachment_definitions) && !model.attachment_definitions.nil?

          update.multipart = true
          create.multipart = true

          model.attachment_definitions.keys.each do |field|
            configure_paperclip_field(field.to_sym)
            # define the "delete" helper for use with active scaffold, unless it's already defined
            ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(model, field)
          end
        end

        def self.included(base)
          base.alias_method_chain :initialize, :paperclip
        end

        private

        def configure_paperclip_field(field)
          columns << field
          columns[field].form_ui ||= :paperclip
          columns[field].params.add "delete_#{field}"

          [:file_name, :content_type, :file_size, :updated_at].each do |f|
            columns.exclude("#{field}_#{f}".to_sym)
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.42 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.41.1 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.41 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.40 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.39 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.38 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.37 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.36 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.35 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.34 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.33 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.32 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.31 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.30 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.29 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.28 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.27 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.26 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
active_scaffold-3.4.25 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb