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)?
views:
73answers:
4
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
2010-03-18 09:42:22
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
2010-03-18 09:55:53
Table name should be plural, thus "users" is fine.
kouak
2010-03-18 11:22:42
Right ! But in his model, the table is probably not named users so he'll have to rename it
Damien MATHIEU
2010-03-18 13:03:56
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
2010-03-18 09:57:10
nice! not something I'm likely to need often, but good to know it's out there.
stephenmurdoch
2010-03-18 13:02:47
I'm bookmarking that one, because it's a PAIN to undo them. Most of the time I just git revert and regenerate.
wesgarrison
2010-03-20 01:19:22