Module: PictureHandler::Mounter::ClassMethods

Defined in:
lib/picture_handler/mounter.rb

Instance Method Summary collapse

Instance Method Details

#storage_field(column, picture_handler) ⇒ Object

Choose the field to action the image with



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/picture_handler/mounter.rb', line 23

def storage_field(column, picture_handler)

  before_save :picture_store
  after_save :picture_delete_old

  before_destroy :picture_delete

  # Save the COLUMN !
  self.column = column

  # Put this uploader in the uploader list
  self.uploaders[column] = picture_handler

  # Inside this class_eval, we are in the instance so you can access Model.picture
  class_eval <<-RUBY

    # Overwrite the field 'storage field' so you can return a formated object instead
    def #{column}
      get_object_or_string(self[__method__.to_sym], __method__)
    end

    def #{column}_versions
      self.send(self.column.to_s).versions_info
    end

  RUBY

end