Rubyonrails-如何为已经存在的模型搭建脚手架?
我已经有一个名为 profile 的模型和相应的数据库表配置文件。 现在我想使用脚手架为此配置文件模型创建增删改查操作。 如何实现这一目标。
I already have a model named profile and corresponding database table profiles.
Now i would like to create crud operations for this profile model using SCAFFOLDING.
how this can be achieved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会同意 Replico 的答案。但如果你真的想使用脚手架,你可以使用:
railsgeneratescaffold_controllerNAME
所以对你来说:
railsgeneratescaffold_controllerProfile
参见
railsgenescaffold_controller--help
代码>了解详细信息。
I'd go with Replico's answer. But if you really want to use scaffold you could use:
rails generate scaffold_controller NAME
so for you:
rails generate scaffold_controller Profile
see
rails generate scaffold_controller --help
for details.
我建议从头开始创建 CRUD 操作,而不是使用脚手架。它将提高您的 Rails 开发技能,并且您不必担心从脚手架生成不必要的代码 - 如果您想为您提供工作基础,请创建一个示例脚手架。
或者,您可以“销毁”模型并在脚手架中重新创建,这根本不会花很长时间。
I would suggest creating the CRUD operations from scratch rather than using scaffold. It'll improve your rails development skills and you don't have to worry about unnecessary generated code from the scaffold - create a sample scaffold if you like to give you a basis to work from.
Alternatively you could 'destroy' the model and recreate in a scaffold, that wont take long at all.