module DynamicImage::BelongsTo::ClassMethods

Public Instance Methods

belongs_to_image(name, scope = nil, **options) click to toggle source
Calls superclass method
# 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