Ask A Question

Notifications

You’re not receiving notifications from this thread.

How To Update ActionText Attachments Discussion

Maybe would be even more generic with GlobalID::Locator.locate_signed(node.attributes['sgid'].value) https://github.com/rails/globalid#signed-global-ids

Reply

If the app key changed, the locator wouldn't be able to verify the SGID, so that would return null. I think you'd need to create a new verifier that still uses the previous key, so something like:

GlobalID::Locator.locate_signed(
  node.attributes['sgid'].value,
  verifier: Verifier.new(oldVerifierHash),
  for: "attachable"
)

Then you could use the replace method from the Fragment and do something like:

ActionText::RichText.where.not(body: nil).find_each do |trix|
  next unless trix.embeds.size.positive?

  trix.update_column :body, trix.body.fragment.replace("action-text-attachment").each do |node|
    return ActionText::Attachment.from_attachable(
      GlobalID::Locator.locate_signed(
        node.attributes['sgid'].value,
        verifier: Verifier.new(oldVerifierHash),
        for: "attachable"
      ),
      node.attributes
    )
  end.to_s
end

Sorry, this is pseudo-code, I don't write Ruby that often. This code was actually a port of a piece of code I wrote using my PHP-port of the ActionText gem, here's a gist:

https://gist.github.com/tonysm/36d2c413b479b29741af9613fb9808ad

There might be better ways, this was just my first take on solving it.

Reply

https://github.com/hotwired/turbo-rails/issues/340

This issue comes with upgrading turbo-rails gem to 1.1.1. Simply downgrading to 1.1.0 will resolve the broken embeds issue. It seems if you use the process in this video and then later decide to downgrade back to 1.1.0---the embeds will remain broken in any ActionText::RichText objects that were changed by this code.

What might the task look like to go the other way---to convert an ActionText::RichText object back to the way it was before this?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.