Ruby-on-rails Rails 路由到唯一索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13937670/
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
Rails route to only index
提问by Butter Beer
This might be a simple routing question in Rails but I have searched around and received answers for Rails 2 rather than Rails 3.
这可能是 Rails 中的一个简单的路由问题,但我已经四处搜索并收到了 Rails 2 而不是 Rails 3 的答案。
I generated a scaffold and the
我生成了一个脚手架和
resources :users
which includes new, edit, show are routed together with the index.
其中包括新建、编辑、显示与索引一起路由。
I only want to route to the index and remove the new, edit, show etc. I have already removed the html.erb files but they are still being routed.
我只想路由到索引并删除新的、编辑的、显示的等。我已经删除了 html.erb 文件,但它们仍在路由中。
Any advice on what I should do to remove the other routes would be appreciated.
任何关于我应该怎么做才能删除其他路线的建议将不胜感激。
回答by Mike Campbell
See Chapter 4.6 of the Rails Routing Guide.
请参阅Rails 路由指南的第 4.6 章。
By default, Rails creates routes for the seven default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the :only and :except options to fine-tune this behavior. The :only option tells Rails to create only the specified routes:
默认情况下,Rails 为应用程序中的每个 RESTful 路由的七个默认操作(索引、显示、新建、创建、编辑、更新和销毁)创建路由。您可以使用 :only 和 :except 选项来微调此行为。:only 选项告诉 Rails 只创建指定的路由:
resources :photos, :only => [:index, :show]

