Skip to content

Enumerating Attachments

Janko Marohnić edited this page Oct 12, 2019 · 1 revision

Shrine doesn't keep a registry of which uploader is used for which attachment on which model. But you can easily retrieve that list using Active Support's Class#subclasses a Ruby's Class#ancestors introspection methods:

ActiveRecord::Base.subclasses.each do |model|
  model.ancestors.grep(Shrine::Attachment) do |attachment|
    model                      #=> Photo
    attachment.shrine_class    #=> ImageUploader
    attachment.attachment_name #=> :image
    attachment.options         #=> {}
  end
end