Ruby-on-rails 如果模型已经存在,如何仅为控制器和视图制作脚手架?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11662392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:45:19  来源:igfitidea点击:

How can I make scaffold only for controller and views if model already exists?

ruby-on-railsruby-on-rails-3scaffoldingscaffold

提问by MKK

I already have set up Deviseto My App.
So User model is already generated, and exists by installing Devise

我已经设置Devise为我的应用程序。
所以用户模型已经生成,并通过安装存在Devise

Now I'd like to add my own controller users_controller.rband its views indexand show.
How can I make scaffold without affecting to User model that already exists?

现在我想添加我自己的控制器users_controller.rb及其视图indexshow.
如何在不影响已经存在的用户模型的情况下制作脚手架?

采纳答案by denis.peplin

For scaffold with only 'name' column:

对于只有“名称”列的脚手架:

rails g scaffold User name --skip

Just add some columns.

只需添加一些列。

Look to rails g scaffold -houtput for additional information.

查看rails g scaffold -h输出以获取其他信息。

回答by RailsEnthusiast

Try this ,

尝试这个 ,

rails g scaffold_controller controller_name 

You will find more options via

您将通过以下方式找到更多选项

rails generate -h

回答by Sabar

If you want just controller and views without the whole scaffold you can do:

如果你只想要控制器和视图而不需要整个脚手架,你可以这样做:

rails generate controller Users index show