lundi 2 septembre 2019

Ruby-on-Rails: route for path with arbitrary number of components?

In my ror application, I want to define a route that will dispatch any length path to a given handler.

I want any URL which begins with http://example.com/xyz/... to go to the same handler, with the full path being passed in as an argument.

In other words, any and all of the following URL's should go to the same handler for the xyz route ...

  • http://example.com/xyz
  • http://example.com/xyz/foo
  • http://example.com/xyz/foo/bar
  • http://example.com/xyz/quack/bark/oink
  • http://example.com/xyz/hip/po/pot/a/mus
  • http://example.com/xyz/[any arbitrary path with any number of components]

... and within the handler, I need to be able to retrieve the entire path that was submitted.

I thought that I should put something like this into config/routes.rb ...

get "xyz/[what goes here?]", to: "xyz#handler"

... but I could not figure out any way to make this work in ror. Am I out of luck?

Aucun commentaire:

Enregistrer un commentaire