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>

85
86
87
88
89
# File 'lib/shrine/plugins/model.rb', line 85

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