Updating old Polls

AI-generated summary

Updating Old Polls to Pie Chart Format

merefield asked if it’s possible to retroactively change a poll to a pie chart format by modifying the inserted text. Falco provided a solution requiring the use of the rails console. To update a poll, run the following commands:

p = Poll.last
p.chart_type = 'pie'
p.save

merefield expanded on this solution, providing a way to quickly find the poll on the rails console if it’s located in the first post of a topic. The steps involve finding the topic and post IDs, then using those to locate the poll:

myPost = Topic.find_by(id: number-from-topic-url).posts.first.id
myPoll = Poll.find_by(post_id: myPost)
myPoll.chart_type = 'pie'
myPoll.save

Alternatively, the process can be condensed into one line:

myPoll = Poll.find_by(post_id: Topic.find_by(id: number-from-topic-url).posts.first.id)
myPoll.chart_type = 'pie'
myPoll.save

Continuing the discussion from Discourse 2.4.0.beta8 Release Notes:

Fantastic to see pie charts! I guess it’s not possible to retro-actively change a Poll to pie chart format e.g. by sneakily inserting chartType=pie into the inserted text? (I couldn’t get it to respond to that change, even on Post Rebake). I was attempting to update some old Polls that would benefit from that presentation. Thanks!

You need to do it on the rails console:

p = Poll.last
p.chart_type = 'pie'
p.save

Just to add to the Solution:

In my case my site usually has the poll in the first post of the Topic, so a quick way of getting to it on the rails console is this:

myPost = Topic.find_by(id: number-from-topic-url).posts.first.id
myPoll = Poll.find_by(post_id: myPost)

or if you really want to go crazy on one line (scroll right!):

myPoll = Poll.find_by(post_id: Topic.find_by(id: number-from-topic-url).posts.first.id)

Then in this case, of course:

myPoll.chart_type = 'pie'
myPoll.save