在Rails 4中自动生成脚手架控制器的路线? [英] Auto-generate routes for scaffolded controller in Rails 4?
问题描述
我正在尝试为一个已经掌握了数据模型的应用程序提供一个快速而又肮脏的Ajax UI,它基本上是通过 rails控制台
到目前为止。无论如何,我以为我会首先从 rails g支架
中自动生成缺少的控制器逻辑,而只能使用 rails g scaffold_controller来获取
(对于现有控制器)。
I'm trying to get a quick-and-dirty Ajax UI going for an app that already has its data model well in hand - it's basically been managed via rails console
so far. Anyway, I thought I would start by auto-generating the missing controller logic that you would get from a rails g scaffold
, only instead with rails g scaffold_controller
for an existing controller.
它创建了控制器,视图和资产。但是它完全没有涉及到路线!它甚至没有尝试,也没有说警告:routes.rb已被修改,没有更改或类似的内容,在 rails g的帮助输出中根本没有提及路由。 scaffold_controller
。
It created the controller, and the views, and the assets.. but it didn't touch the routes at all! It didn't even try, didn't say "warning: routes.rb has been modified, not changing" or anything like that, and there's no mention of routes at all in the help output of rails g scaffold_controller
.
那么我怎么说:请给我您从头开始时会给我的正常路线!
So how do I say "Just give me the normal routes you would have given me if I started from scratch, please!"?
推荐答案
如果我理解这个问题:
请打开config / routes.rb文件,然后在块(routes.draw)内,添加带有表名(多个模型)作为参数的resources方法。像这样:
Please, open the config/routes.rb file, and inside the block (routes.draw) add the resources method with the table name (plural of model) as param. Like this:
MyApp::Application.routes.draw do
resources :products
... # rest of code
end
定义了对产品进行RESTful操作的路径。您可以在此处
That define the routes for RESTful actions over products. You can read more here
在控制台上,您可以运行:耙路
以查看应用程序中的可用路由。
At the console you can run: rake routes
to see the available routes at your app.
这篇关于在Rails 4中自动生成脚手架控制器的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!