rails单数资源仍然是复数? [英] rails singular resource still plural?

查看:101
本文介绍了rails单数资源仍然是复数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索路径,我想将其设为单数,但是当我指定一个单数路径时,它仍然会生成复数个控制器路径,这应该是这样吗?

I have a search route which I would like to make singular but when I specify a singular route it still makes plural controller routes, is this how it's supposed to be?

resource :search

给我

 search POST        /search(.:format)        {:action=>"create", :controller=>"searches"}
 new_search  GET    /search/new(.:format)    {:action=>"new", :controller=>"searches"}
 edit_search GET    /search/edit(.:format)   {:action=>"edit", :controller=>"searches"}
             GET    /search(.:format)        {:action=>"show", :controller=>"searches"}
             PUT    /search(.:format)        {:action=>"update", :controller=>"searches"}
             DELETE /search(.:format)        {:action=>"destroy", :controller=>"searches"}

多个控制器搜索

我实际上只有一条路线...进行搜索:

I only have one route really... to create a search:

所以我做到了: match search => search#create

我只是想知道将来是否仍然应该保留控制器的复数形式? Rails 3.0.9

I'm just wondering for the future if I'm still supposed to keep the controller plural? Rails 3.0.9

推荐答案

是的,这就是应该的样子。引用《 Rails路由指南》:

Yes, that's how it's supposed to be. Quote from the Rails Guide on Routing:


因为您可能希望对单个路由
使用同一控制器(/帐户)和复数路径(/ accounts / 45),单数资源将
映射到复数控制器。

Because you might want to use the same controller for a singular route (/account) and a plural route (/accounts/45), singular resources map to plural controllers.

http://edgeguides.rubyonrails.org/routing.html#singular-resources

这篇关于rails单数资源仍然是复数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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