I noticed that when the attachinary_file_field_options fetches existing attachinary_files associated with my model it serializes the files: [<Attachinary::File ...>] like files: [{ file: { id: 123 ...} }, {file: { id: 456 ...} } ] instead of the correct files: [ {id: 123 ...}, {id: 456, ...} ].
And this makes it go wrong is many ways (remove button doesn't work, posting this option and assigning it to the attachment association makes it delete all associations and recreate them all again, etc.
I was finally able to figure out a fix like this:
require "attachinary/orm/active_record"
module Attachinary
module FileMixin
def as_json(options = {})
super(only: [:id, :public_id, :format, :version, :resource_type], methods: [:path])
end
end
module ViewHelpersExtension
def attachinary_file_field_options(model, relation, options={})
options = super(model, relation, options)
options[:html][:data][:attachinary][:files].map!(&:attributes)
options
end
end
module ViewHelpers
prepend ViewHelpersExtension
end
end
And I add it to the config/initializers/attachinary.rb file. Sounds like it is working properly but I am not sure if this is a bug or if it is something I am doing wrong. All the rest of the configuration is default to what the README instructs.
I noticed that when the
attachinary_file_field_optionsfetches existing attachinary_files associated with my model it serializes thefiles: [<Attachinary::File ...>]likefiles: [{ file: { id: 123 ...} }, {file: { id: 456 ...} } ]instead of the correctfiles: [ {id: 123 ...}, {id: 456, ...} ].And this makes it go wrong is many ways (remove button doesn't work, posting this option and assigning it to the attachment association makes it delete all associations and recreate them all again, etc.
I was finally able to figure out a fix like this:
And I add it to the
config/initializers/attachinary.rbfile. Sounds like it is working properly but I am not sure if this is a bug or if it is something I am doing wrong. All the rest of the configuration is default to what the README instructs.