Code Monkey home page Code Monkey logo

Comments (1)

tsrivishnu avatar tsrivishnu commented on July 24, 2024

Looks like the attachments are not necessarily broken. ActionText is able to find the attachment records with either of the sgids.

The issue is with how we implemented the serialisation and rendering of the rich text. We serialise the attachments separately from the ActionText::Richtext body and match them the sgid in the richtext with the sgid of the separately serialised objects. The objects are serialised with ActionText::Attachable#attachable_sgid.

All the attachments that were attached before v1.2.0 are using the previous sgid in the rich text and the serialised objects are returning a newer sgids. Therefore, our frontend couldn't match them to render appropriately.

I would like to understand why this is happening and if we can make ActionText::Attachable#attachable_sgid to return the old format?

--
For those who might land here, I managed to update the references in the richtext by running the following to update all the attachments in rich text.

require_relative "config/environment"

updated_attachments = []
ActionText::RichText.where.not(body: nil).find_each do |trix|
  next unless trix.body.attachments.size.positive?

  trix.body.fragment.find_all("action-text-attachment").each do |node|
    attachment = ActionText::Attachment.from_node(node)
    next if !attachment.attachable.is_a?(SectionItem)
    puts "attachment: #{attachment}"

    if node.attributes["sgid"].value != attachment.attachable_sgid
      updated_attachments << [
        trix.id,
        node.attributes["sgid"].value,
        attachment.attachable_sgid, # new sgid
        attachment.attachable.class.name,
        attachment.attachable.id,
      ]
    end

    node.attributes["sgid"].value = attachment.attachable_sgid
  end

  trix.update_column :body, trix.body.to_s
end

File.open("updated_attachments.csv", "w") do |f|
  f.puts "trix_id,old_sgid,new_sgid,attachable_type,attachable_id"
  updated_attachments.each { |row| f.puts(row.join(",")) }
end

from globalid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.