RAILS:在更改基础表之后,如何再生脚手架创造的所有观点?

发布于 2025-01-29 04:44:03 字数 336 浏览 5 评论 0原文

Rails的新手,所以请随时编辑我的问题,如果术语错了!

我已经通过脚手架创建了我的MVC,但此后已更改了基础表(重命名了一些列,添加了一些列)。有没有一种方法可以再生用原始脚手架创建的观点以反映我所做的更改?

如果我运行rails g脚手架foo -migration = false -skip我会发现我的模型名称已经在我的应用程序中使用了。

如果删除了整个相应的视图文件夹(由原始支架创建的文件夹),并且我运行rails g脚手架foo -migration = false -force -force生成的视图仍然不会拾取所有我在模型中拥有的字段。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必在意 2025-02-05 04:44:03

您可以扭转脚手架的一代,并重新生成一个新的脚手架,并重命名为新的专栏。

如果您已经迁移了数据库,则需要将其滚回去。

rake db:rollback

然后,您可以扭转脚手架的一代。

rails destroy scaffold MyFoo

然后,使用更新的列生成新的脚手架,

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

否则您可以手动重写视图和控制器,以包括更新的列和新列。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文