如何使用 script/rails 生成添加新操作和视图?
有什么方法可以为现有控制器生成新的操作和视图?我尝试对现有控制器执行以下操作
$ script/rails 生成控制器帖子视图
,其中 view 是我想要添加到控制器的新操作。我知道用手做这件事很简单,但我想知道这是我不知道或我梦想太多的事情。
谢谢 -rr
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 generate controller posts 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.
thanks
-rr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是如此微不足道,只是没有生成器。最好的情况是,您可以将控制器复制到剪贴板中,然后重新生成完整的脚手架(但对您不想修改的视图回答“否”),它将添加视图,并覆盖您的控制器...然后粘贴您的控制器自己的代码回来了......但实际上,到那时,手动添加它们会更容易。
我唯一可能重新生成的时间是早期当我没有正确的模式并且我想让生成器修复我的表单时。
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.