Module: DynamicImage::BelongsTo::ClassMethods

Defined in:
lib/dynamic_image/belongs_to.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_image(name, scope = nil, **options) ⇒ Object


10
11
12
13
14
15
16
17
18
19
# File 'lib/dynamic_image/belongs_to.rb', line 10

def belongs_to_image(name, scope = nil, **options)
  belongs_to(name, scope, options)

  define_method "#{name}=" do |new_image|
    if new_image.present? && !new_image.is_a?(DynamicImage::Model)
      new_image = send("build_#{name}", file: new_image)
    end
    super(new_image)
  end
end