Update "About Category" from the console


(Jay Pfaffman) #1

I’ve got a site with 750+ categories and need to change the text in the “About this category” post to "Blah. Category Name. Blah’.

I’ve tried doing something like this:

desc='Blah. %s Blah.'

c = Category.where("name like '%whatever%'").first
p = Post.where(topic_id: c.topic_id).first
t = Topic.find(c.topic_id)
p.raw = desc % c.name
p.cooked=p.cook(p.raw)
p.save

but it doesn’t change the text in the post, much less the excerpt for the topic or the category description.

What am I missing?


(Gerhard Schlager) #2

Did you try editing the post? I’d replace the last 3 lines of your code snippet with

p.revise(Discourse.system_user, { raw: desc % c.name }, bypass_bump: true)

Can't Update category description post
(Jay Pfaffman) #3

That looks like what I was looking for! I tried to figure out Post.revise, but couldn’t quite get the parameters. Thanks, @gerhard!

And Rails will magically fix up the Topic excerpt and the Category description? (I suppose I’ll know soon enough when I test it tomorrow).