Ruby-on-rails – difference between collection route and member route in ruby on rails

rubyruby-on-rails

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

For example,

resources :photos do
  member do
    get :preview
  end
end

versus

resources :photos do
  collection do
    get :search
  end
end

I don't understand.

Best Answer

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.