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)?
Asked
Active
Viewed 1.4k times
18

samuil
- 5,001
- 1
- 37
- 44
4 Answers
6
update: this script is not supported anymore
A script exists that will do the job for you:

denisjacquemin
- 7,414
- 10
- 55
- 72
-
1nice! not something I'm likely to need often, but good to know it's out there. – stephenmurdoch Mar 18 '10 at 13:02
-
I'm bookmarking that one, because it's a PAIN to undo them. Most of the time I just git revert and regenerate. – wesgarrison Mar 20 '10 at 01:19
-
2Is it possible to use it with rails 3? – mirelon Dec 17 '12 at 14:52
4
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
- 31,924
- 13
- 86
- 94
-
-
Right ! But in his model, the table is probably not named users so he'll have to rename it – Damien MATHIEU Mar 18 '10 at 13:03
4
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.

Damien MATHIEU
- 31,924
- 13
- 86
- 94

shingara
- 46,608
- 11
- 99
- 105
-1
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
- 34,024
- 29
- 114
- 189