ruby on rails 中的收集路线和成员路线之间的区别? [英] difference between collection route and member route in ruby on rails?

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

问题描述

Rails 中的集合路由和成员路由有什么区别?

What is the difference between collection routes and member routes in Rails?

例如

resources :photos do
  member do
    get :preview
  end
end

对比

resources :photos do
  collection do
    get :search
  end
end

我不明白.

推荐答案

成员路由需要一个 ID,因为它作用于一个成员.集合路由不会,因为它作用于对象集合.预览是成员路由的一个示例,因为它作用于(并显示)单个对象.搜索是收集路线的一个例子,因为它作用于(并显示)一组对象.

A member route will require an ID, because it acts on a member. A collection route doesn't because it acts on a collection of objects. Preview is an example of a member route, because it acts on (and displays) a single object. Search is an example of a collection route, because it acts on (and displays) a collection of objects.

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

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