Is there a way to generate a rails scaffold withou

2020-05-15 14:52发布

问题:

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.

回答1:

You can use rails g resource Foo bar:text



回答2:

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.



回答3:

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