Generate a controller with all the RESTful functions

前端 未结 10 1459
遇见更好的自我
遇见更好的自我 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:30

    In Rails 4/5 the following command does the trick for me.

    rails g scaffold_controller Property --skip-template-engine
    

    It generated the controller actions but not the view.

    0 讨论(0)
  • 2021-01-30 08:32

    script/generate rspec_scaffold Property

    0 讨论(0)
  • 2021-01-30 08:33

    There's no way (that I know of? that is documented?) to stub out a controller except through scaffolding. But you could do:

    script/generate controller WhateverController new create edit update destroy show
    
    0 讨论(0)
  • 2021-01-30 08:35

    In Rails 4 it's rails g controller apps new create update edit destroy show index

    Or rails generate controller apps new create update edit destroy show index if you want to write out the full term :).

    0 讨论(0)
  • 2021-01-30 08:40

    In Rails 3 there is also rails generate scaffold_controller .... More info here.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题