Ricky Spanish Ricky Spanish - 26 days ago 19
Ruby Question

Rails: rename globalize column

The rails globalize gem docs are great, but I can't find a solution, what I have to do, when I want to rename a column.

Last Year I did that, to add the translation fields.

def up
remove_column :news, :name
News.add_translation_fields! name: :string
end

def down
add_column :news, :name, :string, default: nil
remove_column :news_translations, :name
end


Now I want to rename the column "name" to "title", without loosing my data and translations. How do I have to write the migration file?

Answer

Alter the column on the news translations table directly:

def change
  rename_column :news_translations, :name, :title
end
Comments