How do I change ActionText Attachment url (domain name)?

We are trying to migrate our Rails app from Heroku to AWS and change the domain name. The problem is that the url in ActionText::Attachment does not change after the data migration. we are using ActiveStorage and S3.

For example.

  • Heroku domain name: heroku.example.com.
  • AWS domain name: aws.example.com.
# app/models/message.rb
class Message < ApplicationRecord
  has_rich_text :content
end
# rails console
> Message.last.content.body.attachments.first
=> #<ActionText::Attachables attachable=#<ActionText::Attachables::RemoteImage:0x00007f3a28669c48 @url="https://heroku.example.com/rails/active_storage/blobs/redirect/xxxxxxxxxx/image.png", @content_type="image/png", @width="92", @height="88">>

As shown above, the URL of the attachment in the ActionText is still heroku.example.com instead of aws.example.com after data migration.

Is there any way to correct the url in ActionText::Attachment to the domain name after the data migration (in this case, aws.example.com)? Or is there a way to modify just the path, not the url?

You can refer to this answer for an example on how to do it: