Is there a way to generate a rails scaffold without the views, there has to be a better way then generating the scaffold and deleting the views and the view specs.
Asked
Active
Viewed 1.3k times
3 Answers
44
You can use rails g resource Foo bar:text
![](../../users/profiles/1251870.webp)
drexin
- 23,521
- 4
- 61
- 79
-
Note it will also do fixtures, yaml and routes. Fixtures and tests will depend on your testing framework. You can also do `rails g model...` and rails generate controller... for more restrictive output. – junky Mar 12 '12 at 19:36
-
6`rails g resource` is what I was looking for. generating the model and then a controller does not create a RESTful controller. – Ibrahim Muhammad Mar 12 '12 at 19:42
-
4`rails g resource` does not generate restful actions inside the controllers. – vishB Nov 18 '15 at 06:29
-
1@whistler See [my answer](http://stackoverflow.com/a/37597087/616644) for how to get the RESTful actions auto generated as well. – Rick Smith Jun 02 '16 at 16:15
16
If you would like to have the controllers generated in the normal fashion, try this:
rails g resource Foo bar:text
rails g scaffold_controller Foo --skip-template-engine
The first command generates the model and the second one uses the generated model to create the controller which includes the RESTful actions.
--skip-template-engine
causes the views to be omitted.
![](../../users/profiles/616644.webp)
Rick Smith
- 8,219
- 13
- 75
- 81
5
Not sure why these answers create the resource first when you can just generate the entire scaffold without the views but still get your controller methods and model.
rails g scaffold Foo bar:string --skip-template-engine
![](../../users/profiles/4725295.webp)
Juan Pablo Ugas
- 908
- 8
- 21