Hello!
When defining multiple routes on the same controller and same action with different named parameters like:
get "/products/:foo", ProductController, :show
get "/products/:foo/:bar", ProductController, :show
get "/products/:foo/:bar/:rebar", ProductController, :show
I would like to be able to call them using the same path name and a different number of arguments.
The product_path function is clearly redefined multiple times but only the first definition is working properly.
iex(1)> MyappWeb.Router.Helpers.product_path
** (UndefinedFunctionError) function MyappWeb.Router.Helpers.product_path/0 is undefined or private. Did you mean one of:
* product_path/3
* product_path/4
* product_path/5
* product_path/6
(myapp) MyappWeb.Router.Helpers.product_path()
iex(1)> MyappWeb.Router.Helpers.product_path(MyappWeb.Endpoint, :show, "1")
"/products/1"
iex(2)> MyappWeb.Router.Helpers.product_path(MyappWeb.Endpoint, :show, "1", "2")
** (Protocol.UndefinedError) protocol Enumerable not implemented for "2". This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Scrivener.Page, Stream, Timex.Interval
iex(2)> MyappWeb.Router.Helpers.product_path(MyappWeb.Endpoint, :show, "1", "2", "3")
** (Protocol.UndefinedError) protocol Enumerable not implemented for "3". This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Scrivener.Page, Stream, Timex.Interval
If it’s not possible to redefine the same route path on a different number of named argument, would it be possible to have a good warning message or a better exception?
In that case, why the path is still correctly redefined?
Thanks.