Rails: is there a way to specify the controller for a route at runtime?
I'm developing a versioned API and would like routes to resolve to controllers in much the same way that bundler works, e.g. find the highest version controller <= the version asked for in the route...
Because there are an infinite number of minor versions between two indexes, I don't want staticly route with explicite routes. I'm hoping for a way to use a block to map incoming requests with the appropriate controller.
Given
/app/controllers/api/v1.5.2/users_controller.rb
/app/controllers/api/v2.3.5/users_controller.rb
Route
GET /api/v1.5.2/user --> ~/v1.5/users_controller.rb
GET /api/v1.6.1/user --> ~/v1.5/users_controller.rb
GET /api/v1.7.7/user --> ~/v1.5/users_controller.rb
...
GET /api/v2.3/user --> ~/v2.3/users_controller.rb
Aucun commentaire:
Enregistrer un commentaire