资源和Rails路由中的资源之间的区别? [英] Difference between resource and resources in rails routing?

查看:60
本文介绍了资源和Rails路由中的资源之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资源资源在铁路路线中有什么区别

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来告诉路由器苹果要检索的苹果。如果我已经有一个苹果,那么就不需要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

在您的示例中:


  1. 控制器 geocoder是单个资源,可用于编辑,创建,更新等。

  2. 控制器 posts,是一种复数资源,将处理您可以索引,编辑,创建等等的传入通用帖子。

这篇关于资源和Rails路由中的资源之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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