views:

73

answers:

4

I made a mistake early in development, and named one of my models with plural noun (Users instead of User). Is there an easy way to rename it and corresponding controller (similar to generating it with script/generate way)?

A: 

no easy way that I know of, http://railsforum.com/viewtopic.php?id=32693

i think you've just got to do it manually

don't forgt to rename all your tests too....

stephenmurdoch
A: 

You'll have to change all the references to Users in all your application manually.

To change the name by itself, it's not very hard : rename the file and add the following migration :

class RenameUsers < ActiveRecord::Migration
    def self.up
        rename_table :users, :user
    end
    def self.down
        rename_table :user, :users
    end
end
Damien MATHIEU
Table name should be plural, thus "users" is fine.
kouak
Right ! But in his model, the table is probably not named users so he'll have to rename it
Damien MATHIEU
A: 

You need to rename your file, your test/spec file and all reference to this model.

You also need to make a migration to rename the table.

shingara
+2  A: 

Hi,

A script exist and will do the job for you

http://github.com/hiroshi/script-refactor

Cheers

denisjacquemin
nice! not something I'm likely to need often, but good to know it's out there.
stephenmurdoch
I'm bookmarking that one, because it's a PAIN to undo them. Most of the time I just git revert and regenerate.
wesgarrison