Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename model

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)?

like image 266
samuil Avatar asked Mar 18 '10 09:03

samuil


2 Answers

update: this script is not supported anymore

A script exists that will do the job for you:

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

like image 178
denisjacquemin Avatar answered Sep 28 '22 18:09

denisjacquemin


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
like image 44
Damien MATHIEU Avatar answered Sep 28 '22 16:09

Damien MATHIEU