Reputation: 13368
Let's say I have a controller and model called Car/Cars in Rails. Then I wanna change it to Vehicle/Vehicles. How to I achieve that?
Upvotes: 1
Views: 3455
Reputation: 1198
To install: gem install rails_refactor
Before use, make sure you cd to the root of your rails project.
To rename a controller:
rails_refactor rename OldController NewController
renames controller file & class name in file
renames controller spec file & class name in file
renames view directory
renames helper file & module name in file
updates routes
To rename a controller action:
$ rails_refactor rename DummyController.old_action new_action
renames controller action in controller class file
renames view files for all formats
To rename a model:
$ rails_refactor rename OldModel NewModel
renames model file & class name in file
renames spec file & class name in file
renames migration & class name & table names in file```
Upvotes: 0
Reputation: 2909
Things to take care of when changing controller name
class XxxController < ApplicationController
routes.rb
*_path
and *_url
URL helper
instancesUpvotes: 0
Reputation: 25774
I don't know if there's any sort of automated process in Rails to do this. It boils down to a lot of find/replace for your instances of Car
with Vehicle
and cars
with vehicles
, as well as in all filenames, routes, and the database.
Upvotes: 2
Reputation: 46914
You need change the name of file, the name of director and in last, the name of Class.
Upvotes: 3