Module: Shrine::Plugins::Model::AttacherClassMethods

Defined in:
lib/shrine/plugins/model.rb

Instance Method Summary collapse

Instance Method Details

#from_model(record, name, **options) ⇒ Object

Initializes itself from a model instance and attachment name.

photo.image_data #=> "{...}" # a file is attached

attacher = Attacher.from_model(photo, :image)
attacher.file #=> #<Shrine::UploadedFile>


83
84
85
86
87
# File 'lib/shrine/plugins/model.rb', line 83

def from_model(record, name, **options)
  attacher = new(**options)
  attacher.load_model(record, name)
  attacher
end