Route Globbing and Path Helpers
Problem
Given this url /api/:version/heroes/*publishers
:
- the generated path helper function is
api_v1_heroes_publishers_path
- the generated url when calling the function is
/api/v1/heroes/publishers.json
- there is no way to set the value of
publishers
parameter using the path helper. Eg. we can't doapi_v1_heroes_publishers_path(publishers:'marvel,dc_comics')
- the path helper is not usable as it doesn't accept any parameter and it always generates the same url.
Proposition
Shouldn't this be more aligned with what Rails is doing. For example, if in routes.rb
, there is this code snippet:
namespace :api do
namespace :v1 do
get '/heroes(/*publishers)' => 'heroes#get_them', as: :heroes
end
end
then
- the generated path helper function is
api_v1_heroes_path
(nopublisher
in the name) - it has a single required parameter that will be mapped to
params[:publishers]
- generated urls are:
api_v1_heroes_path("marvel,dc_comics")
=>/api/v1/heroes/marvel,dc_comics
Example
https://gitlab.com/10io/wildcard-segment
Credits
@nkipling for raising this issue.