I think the biggest problem for this is that it might encourage abuse of the feature. While this might make sense for a few items (like small, medium and large photo; or all, pending and completed todo items - in these case I think it makes more sense to define them as routes than handling them in the controller), I think it would be a very bad idea to pass it an array of country codes as an example.
What I would like to do in that case though, would be to do something like:
[:all, :pending, :completed].each do |filter|
get “items/#{filter}”, to: “items#index”, as: “#{filter}_items”
end
Of course in here there needs to be a way for the router to communicate type of filter to the controller. So what I would like to have is actually this:
[:all, :pending, :completed].each do |filter|
get “items/#{filter}”, to: “items#index”, as: “#{filter}_items”, extra_params: { filter: filter }
end
This would produce more or less the same result as what the OP wanted, but generates nicer URL helpers (IMO), much more explicit and provides a more general mechanism that can be used in other cases.
(I thought about using defaults, but that wouldn’t work because it can be override in the query string. These also seem to be a requirements hash for resource routes which might do this, but it doesn’t look like it exists for non-resource routes.)
However, these extra params would be used for incoming routes but not for URL generation which you could argue is a weird semantic.
The alternative would be to pass these to different (non-restful) actions on the controller and within the controller they could pass it onto a common private method.
Godfrey