I'm terrible at naming and realize that there are a better set of names for my models in my Rails app. Is there a way to use a migration to rename a model and its table?
+16
A:
Found the answer at http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations#rename_table.
Here's an example:
class RenameOldTableToNewTable< ActiveRecord:Migration
def self.up
rename_table :old_table_name, :new_table_name
end
def self.down
rename_table :new_table_name, :old_table_name
end
end
I had to go and rename the model declaration file manually.
Readonly
2009-01-23 00:29:42
Yes but this doesn't change the name of the model, does it?
ryeguy
2010-01-29 21:37:36
it changes only the table name.
j.
2010-03-03 18:58:22
Does this mean you have to rename the Controller and View folders/files manually as well? Are those all of the things to manually rename?
Teef L
2010-04-24 06:35:01
@mathee: yes, you have to change that manually, or using an IDE that can do Ruby refactoring and commit it to your version control system.
J. Pablo Fernández
2010-04-30 09:00:05