如何使用脚本/导轨生成添加新动作和视图? [英] How do I add new action and view with script/rails generate?

查看:38
本文介绍了如何使用脚本/导轨生成添加新动作和视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以为现有控制器生成一个新的动作和视图?我尝试对现有控制器进行以下操作

There is any way to generate a new action and view to an existing controller ? I've tried to do following to an existing controller

$ script/rails 生成控制器帖子视图

$ script/rails generate controller posts view

其中 view 是我想添加到控制器的新操作.我知道手工操作很简单,但我想知道是我不知道还是我梦想太多.

where view is the new action which I want to add to controller. I know it's trivial to do it by hand but I'm wondering is something which I don't know or I dream to much.

谢谢-rr

推荐答案

这太琐碎了,只是没有生成器.充其量您可以将您的控制器复制到剪贴板,然后重新生成完整的脚手架(但对您不想修改的视图回答否"),它将添加视图,并覆盖您的控制器......然后粘贴您的自己的代码回来......但实际上,到那时手动添加它们会更容易.

It's so trivial, there's just no generator for it. At best you could copy your controller into your clipboard, and then regenerate the complete scaffold (but answer no to the views that you don't want modified) and it will add the view, and overwrite your controller... and then paste your own code back... but really, by that point it would have been easier to just add them by hand.

我唯一可能重新生成的时间是在我没有正确的模式并且我想让生成器修复我的表单的早期.

The only time I might regenerate is early on when I didn't have my schema right and I want to let the generator fix my form.

这篇关于如何使用脚本/导轨生成添加新动作和视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆