Amethi is trying to use the rake posts:remap command to replace broken images left over from a forum migration to Discourse. However, the command is not finding any posts to replace, despite there being thousands of posts with the target elements.
The goal is to replace <img src="https://londonbikers.com/images/transparent.png" alt="... with <img src="https://londonbikersarchive.blob.core.windows.net/forum-attachments/... while keeping the alt tag contents. Amethi has attempted to escape double quotes with backslashes, but this is not working.
Pfaffman suggests that the images may be stored in the raw field, which is the text seen in the editor, rather than the cooked field, which is the processed text displayed on the site. Pfaffman recommends using Ruby in the Rails console to rewrite the posts instead of the rake posts:remap command, as it avoids multiple levels of escaping. An example Ruby code snippet is provided to get started.
Amethi is unsure about the raw field and asks for clarification on what to do in the Rails console.
I’m trying to find and replace some broken images left over from our forum migration to Discourse and have had great success (love the remap command!) but it’s not finding anything to replace for these examples and I can’t see anything wrong, can you?
Oh, hang on, some of these images are working. Is this Discourse attachment functionality? Is there some custom rendering logic going on as opposed to these being HTML strings in the database?
But this one doesn’t. I can have the file in cloud blob storage so would either like to import it into Discourse or just have it referenced from blob storage:
raw is the field where the text you see in the editor is. The stuff you are replacing is what you see if you edit the post in the ux, right? (cooked is the stuff that’s been processed and is what gets displayed.)
Doing stuff to re-write the posts. This is might be just enough to make you dangerous:
bps = Post.where("raw like '%//SOME-STRING%'")
bps.each do |post|
post.raw.gsub!(/OLD/,'NEW')
post.save
end
The advantage over the rake task is that you don’t have multiple levels of espaping to navigate.