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
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.
script/generate rspec_scaffold Property
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
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 :).
In Rails 3 there is also rails generate scaffold_controller ...
. More info here.
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.