简体   繁体   中英

In Rails, how do you generate the show view from an existing model?

Let's say you already have a model, but want to generate the show view that would normally be generated as if you generated that model via a scaffold. Is there a generator you can invoke to generate a show view from an existing model?

The command would look like:

rails g show_view User

I'd also want this to pick up the properties from my existing model and write them as fields into the views.

you need to use scaffold_controller

$ rails g scaffold_controller User

More info about 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. 

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