Escaping a backslash in a regex

I don’t know off hand if this would work or not

Since you want to only replace “T8” with “T9”. Maybe remove all slashes and test?

In your syntax error it shows your missing quotes

SyntaxError: unexpected integer literal, expecting ')'
  topic.title.gsub!(/T8/2024/,"T9/2024")
                        ^~~~

Maybe try this fixed missing quotes

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

Also removed extra “/”

1 Like