Is it possible to override a RESTful path?
For instance, I have photo_path(photo) which would generate /photos/12345
But I’d like for all uses of photo_path to actually generate URL’s like /photos/joeschmoe/12345 (which is the photo’s user and the photo id).
Obviously I could just create a new route, but wanted to make sure there wasn’t a more RESTful way of doing it.
You could make photos a sub-resource to user’s, so you’d have
users/joeschmoe/photos/12345(of course here, your users controller would require the ability to accept a username instead of an id, which is another routing problem to solve but not difficult)Then your controller could maybe call
Although I think there are less hacky ways of doing that.
You could also add
joeschmoeas a query string parameter.Or you could make username an optional parameter in the route, so it would be something like
Or if you want a new named route: