Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The attachment files options may be serialized in the wrong way #136

Open
akitaonrails opened this issue Sep 7, 2016 · 0 comments
Open

Comments

@akitaonrails
Copy link

akitaonrails commented Sep 7, 2016

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.

@akitaonrails akitaonrails changed the title The JS side files options may be serialized in the wrong way The attachment files options may be serialized in the wrong way Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant