简体   繁体   English

Rails:对基础表进行更改后,如何重新生成脚手架创建的所有视图?

[英]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! Rails 新手,所以如果我弄错了术语,请随时编辑我的问题!

I've created my MVC via scaffold, but have since made changes to the underlying table (renamed some columns, added some columns).我已经通过脚手架创建了 MVC,但后来对基础表进行了更改(重命名了一些列,添加了一些列)。 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.如果我运行rails g scaffold Foo --migration=false --skip我会收到一个错误,即我的模型名称已在我的应用程序中使用。

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.如果删除整个相应的视图文件夹(由原始脚手架创建的文件夹),并且我运行rails g scaffold Foo --migration=false --force生成的视图仍然没有拾取我模型中的所有字段。

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.否则,您可以手动重写视图和控制器以包含更新的列和新列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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