简体   繁体   中英

Rails: How can I regenerate all the views created by scaffold after I make changes to the underlying table?

New to Rails, so please feel free to edit my question should I get the terminology wrong!

I've created my MVC via scaffold, but have since made changes to the underlying table (renamed some columns, added some columns). Is there a way to regenerate the views that were created with the original scaffold such that they reflect the changes I've made?

If I run rails g scaffold Foo --migration=false --skip I get an error that my model name is already used in my application.

If delete the entire corresponding views folder (the one created by the original scaffold), and I run rails g scaffold Foo --migration=false --force the views generated still don't pick up all the fields I have in my model.

You could reverse the scaffold generation and regenerate a new scaffold with renamed and new columns.

If you already migrated the database you will need to roll it back.

rake db:rollback

Then you can reverse the scaffold generation.

rails destroy scaffold MyFoo

Then generate new scaffold with updated columns

rails generate scaffold MyFoo column_name_1:data_type column_name_2:data_type column_name_3:data_type

Otherwise you can manually rewrite your views and controllers to include the updated and new columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM