是否可以为具有不同名称且不直接与我的模型名称关联的现有模型生成和搭建支架?
假设我有这个模型 Post
并且我已经有一个名为 posts_controller
的控制器,但我已经在使用了一堆方法,但只是时间问题我需要生成一个脚手架来通过模型 Post
填充我的表格帖子,但如果我尝试
rails gscaffold Post field:type.... --skip--migration
生成器仍然会创建一个名为posts_controller
可以指定它使用/生成的控制器名称:my_awesome_scaffold_controller
?
谢谢。
=======更新========
我想要在my_awesome_scaffold_controller
中拥有的是我的模型帖子index
的完整支架,新建
、编辑
、显示
、创建
、更新
、删除
对于 Post
模型,不使用post_controller
with 已经用于其他人完成的其他事情,我不想弄乱那里的代码。
Is is posible to generate and scaffold for an existing model with a different name not associated directly to the name of my model?
Let's say I have this model Post
and I already have a controller named posts_controller
but I have a bunch of methods there that I'm already using, but as a matter of time I need to generate an scaffold to fill in my table posts trough the model Post
but if I try
rails g scaffold Post field:type.... --skip--migration
The generator would still be looking to create a controller named posts_controller
is is possible to specify the controller name It'd using/generating to something like: my_awesome_scaffold_controller
?
Thanks.
======= UPDATE ========
What I want to have in my_awesome_scaffold_controller
is the complete scaffold for my model post index
, new
, edit
, show
, create
, update
, delete
for the Post
model without using the post_controller
with is already in use for other stuff done by somebody else and I don't wanna mess up the code there.
发布评论
评论(1)
好吧...我不相信你所做的比仅仅将现有的 posts_controller 移到其他地方(例如图书馆或其他地方)更好,但要忠实于你实际要求的内容...
一个选项(如果您不介意将操作添加回 posts_controller)
显然,如果 posts_controller 已经具有任何 RESTful 操作,则这将不起作用 - 也这意味着您和其他人正在处理同一个文件(尽管可能是不同的区域)。
或者,您可以为脚手架命名空间。类似于
admin/posts_controller.rb
(或者在您的情况下:my_awesome/posts_controller.rb
)这里有一个关于此的旧教程:http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding
无法保证它对您有多好/相关。
ok... I'm not convinced that what you're doing is better than just, say, moving the existing posts_controller away somewhere else (eg a library or whatever) but to stay true to what you actually asked...
One option (if you don't mind adding the actions back into posts_controller)
obviously this won't work if the posts_controller already has any of the RESTful actions - also it means you and the other person are working on the same file (though likely different areas).
Alternatively you could name-space your scaffold. Similar to
admin/posts_controller.rb
(or in your case:my_awesome/posts_controller.rb
)There's an old tutorial on this here: http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding
Can't vouch for how good/relevant it is for you.