Included
The included
plugin allows you to hook up to the .included
hook
of the attachment module, and call additional methods on the model that
includes it.
plugin :included do |name| # called when attachment module is included into a model self #=> Photo (the model class) name #=> :image endend
include ImageUploader::Attachment(:image) # triggers the included block end
For example, you can use it to define additional methods on the model:
plugin :included do |name| define_method(:" _width") { send(name)&.width } define_method(:" _height") { send(name)&.height } endend
photo = Photo.new(image: file)photo.image_width #=> 1200 photo.image_height #=> 800