假设您已经有了一个模型,但想要生成通常会生成的显示 View ,就像您通过脚手架生成该模型一样。是否有可以调用的生成器来从现有模型生成显示 View ?
命令看起来像:
rails g show_view User
我还希望它从我现有的模型中获取属性并将它们作为字段写入 View 。
最佳答案
你需要使用scaffold_controller
$ rails g scaffold_controller User
关于scaffold_controller
的更多信息
Stubs out a scaffolded controller and its views. Pass the model name, either >CamelCased or under_scored, and a list of views as arguments. The controller name is >retrieved as a pluralized version of the model name.To create a controller within a module, specify the model name as a path like 'parent_module/controller_name'.
This generates a controller class in app/controllers and invokes helper, template engine and test framework generators.
关于ruby-on-rails - 在 Rails 中,如何从现有模型生成显示 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16652791/