The Rails routing guide doesn't specify what :on => :collection
means.
I cannot find an explanation to what the :on
key is, nor what a :collection
is in that context.
Rails routes on resources support member routing as well as collection routing. Member routes act on a member of the resource. Collection routes acts on resources in general.
Collection Route means a route established by the designated officer, covering an area within which waste will be collected by the city.
Considering the same case, the two terms can be differentiated in a simple way as :member is used when a route has a unique field :id or :slug and :collection is used when there is no unique field required in the route.
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.
Routes on collections are listed here.
The difference between :on => :collection
and :on => :member
are the style of route they produce and their associated route helpers.
resources :posts do # on collection get 'search', on: :collection # --> generates '/posts/search' and search_posts_path # on member get 'share', on: :member # --> generates'/posts/:id/share' and share_photo_path(@post) end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With