Sha256: 2a3a4a092f518f8c32678c88d3448a86326a460db0529d500c31d14a1e0e8a2b

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

module ActiveScaffold
  module PaperclipBridge
    def initialize_with_paperclip(model_id)
      initialize_without_paperclip(model_id)
      return if self.model.attachment_definitions.nil?

      self.update.multipart = true
      self.create.multipart = true

      self.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
        PaperclipBridgeHelpers.generate_delete_helper(self.model, field)
      end
    end

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brisk-bills-0.8.2 vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge.rb
brisk-bills-0.8.1 vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge.rb