root/vendor/plugins/has_attachment/lib/has_attachment.rb

Download in other formats: Raw | Text
Revisions
Dimitrij Denissenko
Dimitrij Denissenko
Dec 06 2009 * 18:24
(9 months ago)

Revision b164a101261ae03572321128da49703ba483e311

Added multi-storage (AWS/S3) functionality to attachments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'attachment'
require 'has_attachment/storage'

module HasAttachment
  
  def self.included(base)
    base.extend ClassMethods 
  end
  
  module ClassMethods

    def has_attachment(options = {})
      has_one :attachment, options.merge(:as => :attachable)
      include InstanceMethods
      alias_method_chain :attachment=, :validation
    end

  end

  module InstanceMethods

    def attachment_with_validation=(value)
      self.attachment_without_validation = Attachment.parse(value)
    end
    
  end
  
end

ActiveRecord::Base.class_eval do
  include HasAttachment
end