Generate a controller with all the RESTful functions

前端 未结 10 1570
遇见更好的自我
遇见更好的自我 2021-01-30 07:58

I am trying to generate a controller with all the RESTful actions stubbed. I had read at Wikibooks - Ruby on Rails that all I needed to do was to call the generator with the co

10条回答
  •  粉色の甜心
    2021-01-30 08:40

    You're looking for scaffolding.

    Try:

    script/generate scaffold Property
    

    This will give you a controller, a model, a migration and related tests. You can skip the migration with the option --skip-migration. If you don't want the others, you'll have to delete them yourself. Don't worry about overwriting existing files, that won't happen unless you use --force.

    As klew points out in the comments, this also defines the method bodies for you, not just the names. It is very helpful to use as a starting point for your REST controller.

提交回复
热议问题