How to re-name a ActiveRecord Model which can automatically change the table name in DB?

后端 未结 4 1442
野趣味
野趣味 2021-02-04 05:21

I have a Active Record model \"car\", I would like to change the name of this model to \"train\" without changing functionalities inside, that\'s only

4条回答
  •  我寻月下人不归
    2021-02-04 06:07

    I used following steps to rename my model

    In sublime text:

    1. press cmd + shift + find and choose case-sensitive search (see left buttons). It will search word in whole project
    2. search and replace 'Cars' to 'Trains'
    3. search and replace 'Car' to 'Train'
    4. search and replace 'car' to 'train'
    5. rails generate migration rename_cars_to_trains
    6. manually change following file names

      • cars_controller
      • car_helper
      • Model/ car.rb
      • all related files in test folder
    7. change folder name in views: cars to trains

提交回复
热议问题