I am using Rails 3.1.1 and Ruby 1.9.2. I am moving a database from a Ruby 1.8.7 environment to a Ruby 1.9 environment and would like to execute the following migration:
# coding: utf-8
class CleanseVerses < ActiveRecord::Migration
def up
Poem.all.each do |vs|
cleansed_text = String.new
cleansed_text = vs.text
cleansed_text.gsub!('—', '—')
cleansed_text.gsub!(' - ', ' — ')
cleansed_text.gsub!('’', '’')
cleansed_text.gsub!('“', '“')
cleansed_text.gsub!('â€', '”')
cleansed_text.gsub!('prince', 'king')
vs.text = cleansed_text
vs.save
end
end
def down
end
end
The problem is that the database doesn't seem to reflect any of the changes. Even the simple 'prince' to 'king' conversion isn't working.
I do have attr_accessible on the Poem.text field.
Am I missing something fundamental on strings?
UPDATE:
It seems that I am missing something fundamental on the nature of strings.
When I change the following two lines:
cleansed_text = String.new
cleansed_text = vs.text
to
cleansed_text = String.new(vs.text)
then everything works perfectly.