How to replace a string/character in topic title?

Here’s my try. It’s not tested, so please backup first!

I don’t know how this interacts with “encoded”. Perhaps that means that dashes are encoded as something other than a -. If that’s the case, you’ll need to modify things accordingly.

Topic.where("title LIKE '%-%'").find_each do |topic|
  topic.title.gsub!(/-/," ")
  topic.fancy_title.gsub!(/-/," ")
  topic.slug.gsub!(/-/," ")
  puts topic.title
  begin
    topic.save!
  rescue
    puts "oops, something broke."
  end
end
1 Like