Is there a way to generate a rails scaffold withou

2020-05-15 14:49发布

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.

3条回答
贼婆χ
2楼-- · 2020-05-15 15:18

You can use rails g resource Foo bar:text

查看更多
倾城 Initia
3楼-- · 2020-05-15 15:22

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
查看更多
贪生不怕死
4楼-- · 2020-05-15 15:37

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.

查看更多
登录 后发表回答