views:

127

answers:

5

Hello,

I am trying to generate a controller with all the RESTful actions stubbed. I had read at link text that all I needed to do was to use call the generator with just a controller name I would get just that. So, I ran "script/generate rspec_controller Properties" and I got an empty controller.

Any other suggestions would be greatly appreciated.

A: 

try using scaffolding.

script/generate scaffold controller Properties

Section of Official docs on Ruby On Rails

I'm sure you can find more info if you do a google search on rails scaffolding. Hope that helps.

Nick Gorbikoff
can you script/generate rspec_scaffold controller Properties?
Barb
yes you could. Here is detailed info/tutorial: http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/
Nick Gorbikoff
A: 

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
thenduks
Great answer, I think you are missing an action are there not 7 actions?
Barb
Yea sorry I forgot `index`
thenduks
+2  A: 

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.

molf
@Barb, I think Scaffolding would be better for you since it not only declares all functions but it also defines them. It is good to create them at least once and have them as an example.
klew
+1  A: 

I don't know about an automated way of doing it, but if you do:

script/generate controller mycontroller new create update edit destroy index show

All of them will be created for you

Marcos Placona
Great Answer. Experts can ignore the rest. Note to noobs - if you name your controller PropertyController as I misunderstood :) you will get PropertyController Controller :)
Barb
My answer does exactly the same thing - except you don't need to specify all of the default 7 actions.
Nick Gorbikoff
A: 

script/generate rspec_scaffold Property

stephenmurdoch
and yes, I realise that you have already accepted an answer on this one, but I feel this solution might help some people who read this post out too.... the solution above will create a model etc, which you can just delete if you don't need
stephenmurdoch