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

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

问题描述

rails路由中resourceresources有什么区别

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

在你的例子中:

  1. 控制器地理编码器"是一个单一的资源,可用于编辑、创建、更新等.
  2. 控制器帖子"是一种复数资源,用于处理传入的通用帖子,您可以对其进行索引、编辑、创建等操作

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

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