I have created a poll on my forum like:
[poll name=freestyle type=multiple results=always min=1 max=14 public=true chartType=bar]
* **#1** 
* **#2** 
[/poll]
I migrated from a CDN to no CDN, and the URLs were changed from cdn.unicyclist.com to unicyclist.com.
However, the images URLs here remains broken, despite appearing in the post preview:
Rebaking posts and running rake 'posts:remap[cdn.unicyclist.com,unicyclist.com]' didn’t fix it.
ask.discourse.org advises:
What’s probably happening
Your poll options are not only in the post raw. On your site schema, polls also store rendered option HTML in:
pollspoll_options.htmlSo the post preview can look fine, but the poll renderer may still be using stale HTML with the old CDN hostname.
Related docs:
- Creating and managing polls
- Remove DISCOURSE_CDN_URL
- Disable CDN causes old images with CDN URL can not be shown
- Replace a string in all posts
Important warning
Take a full backup first.
Also, avoid “just editing” the poll if it has votes, because poll edits normally clear votes:
Safer approach: inspect one broken poll first
In the container:
cd /var/discourse ./launcher enter app rails cThen find the poll for that post:
poll = Poll.find_by(post_id: POST_ID, name: "freestyle") PollOption.where(poll_id: poll.id).pluck(:id, :html)If you see
cdn.unicyclist.comin that HTML, that confirms it.Fix that one poll
poll = Poll.find_by(post_id: POST_ID, name: "freestyle") PollOption.where(poll_id: poll.id).find_each do |opt| new_html = opt.html.gsub("cdn.unicyclist.com", "unicyclist.com") opt.update_columns(html: new_html, updated_at: Time.zone.now) endThen rebake that post too:
Post.find(POST_ID).rebake!If it works, bulk-fix all poll options
PollOption.find_each do |opt| next unless opt.html&.include?("cdn.unicyclist.com") opt.update_columns( html: opt.html.gsub("cdn.unicyclist.com", "unicyclist.com"), updated_at: Time.zone.now ) endWhy
posts:remapdidn’t helpBecause that rake task is for post content, while your broken image references are probably sitting in the poll option HTML cache instead:
Recommendation
- test on one broken poll
- confirm the images load
- only then run the bulk fix
If you want, I can write you a copy-paste script where you only replace
POST_IDand run it safely on a single poll first.
Does that look good to you? I’ll do a backup first obviously, but I prefer to avoid having to restore my forum.
I need to keep all poll results ![]()
Bonus question: should Discourse natively handle those cases?
