views:

3334

answers:

1

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
Yes but this doesn't change the name of the model, does it?
ryeguy
it changes only the table name.
j.
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
@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