rails路由中资源和资源的区别? [英] Difference between resource and resources in rails routing?
问题描述
rails 路由中resource
和resources
的区别是什么
what is the difference between resource
and resources
in rails routing
resource :geocoder
和
resources :posts
它们之间的真正区别是什么?
What is real difference between them ?
推荐答案
本质上,路由资源是指资源为控制器提供操作能力.
In essence, routing resources is when resources gives action abilities to a controller.
http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
如果使用复数资源作为处理对任何项目的通用请求的一种方式,那么单一资源就是处理手头当前项目的一种方式.
If a pluralized resources is used as a way to handle generic requests on any item, then a singular resource is a way to work on the current item at hand.
所以换句话说,如果我有一组苹果,要检索特定的苹果,我必须通过发送苹果的 ID 来告诉路由器苹果"要检索的苹果.如果我已经有一个 Apple,则不需要 ID.
So in other words, if I have a collection of Apples, to retrieve a specific apple, I'd have to tell the router "Apples" what apple to retrieve by sending the ID of the apple. If I already have one Apple, then an ID is not needed.
通过查看它们具有哪些操作(或路由)来注意两者之间的差异:
Notice the differences between the two by looking at what actions (or routes) they have:
- 资源:索引、新建、创建、显示、编辑、更新、销毁
- 资源:新建、创建、显示、编辑、更新、销毁
- resources: Index, new, create, show, edit, update, destroy
- resource: new, create, show, edit, update, destroy
在你的例子中:
- 控制器地理编码器"是一种单一资源,您可以使用它来编辑、创建、更新等.
- 控制器posts"是一个复数资源,它将处理传入的通用帖子,您可以索引、编辑、创建......等
这篇关于rails路由中资源和资源的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!