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,因为它作用于 member.集合路由不会,因为它作用于对象集合.预览是成员路由的一个示例,因为它作用于(并显示)单个对象.搜索是收集路线的一个例子,因为它作用于(并显示)一组对象.

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.