Currently the content block model defines dynamically a class to manage attachments declared in the manifest using uploaders. In this way the class can mount the carrierwave uploaders defined for each image in the manifest. With ActiveStorage migration we have some alternatives:
- To try to define the same class adapting the trick and defining with
has_one_attached the attachments defined in the manifest. It requires some research because ActiveStorage has a lot of dependencies with the other parts of Rails framework, and even if we declare the dynamic class inherited from ActiveRecord::Base, some methods provided by ActiveStorage fail.
- To add a
has_many_attached :images to content block model and perform validations in the class. This approach has some limitations, the has_many_attached relation doesn't allow us to differentiate the images to associate them with each definition in the manifest. We could insert the name of the attribute in the metadata attribute of the blob, but it seems that metadata is an internal attribute and there is no public methods to manage it
- To add a
has_many association with Decidim::Attachment. There is a lot of functionality there not required for content blocks attachments, but we can use one of the attributes to differentiate the images
- To create a new model for content block attachments. A content block
has_many :attachments and each attachment has_one_attached :file. The validations can be done looking at the uploader defined by the manifest
I think that the last alternative is the best solution, but it involves maintaining a new model
Currently the content block model defines dynamically a class to manage attachments declared in the manifest using uploaders. In this way the class can mount the carrierwave uploaders defined for each image in the manifest. With ActiveStorage migration we have some alternatives:
has_one_attachedthe attachments defined in the manifest. It requires some research because ActiveStorage has a lot of dependencies with the other parts of Rails framework, and even if we declare the dynamic class inherited from ActiveRecord::Base, some methods provided by ActiveStorage fail.has_many_attached :imagesto content block model and perform validations in the class. This approach has some limitations, the has_many_attached relation doesn't allow us to differentiate the images to associate them with each definition in the manifest. We could insert the name of the attribute in the metadata attribute of the blob, but it seems that metadata is an internal attribute and there is no public methods to manage ithas_manyassociation with Decidim::Attachment. There is a lot of functionality there not required for content blocks attachments, but we can use one of the attributes to differentiate the imageshas_many :attachmentsand each attachmenthas_one_attached :file. The validations can be done looking at the uploader defined by the manifestI think that the last alternative is the best solution, but it involves maintaining a new model