I have a situation where I’m in need to constructing pretty url paths.
I have a FilesController that need to handle URLs like:
mydomain.com/files/path/dir1/dir2/user/bob
mydomain.com/files/path/dir1/user/bob
mydomain.com/files/path/dir1
mydomain.com/files/user/bob
In the controller, I want params[:path] to contain everything between /path and /user and params[:user] to contain anything after /user (assuming only one user and it’s optional).
I’m looking for the best way to do this, preferable with just one statement in the routes.rb file. The trickiest part, I think, is that after /path an actual path to a file might be provided, N times deep.
You want route globbing:
You might also need to add an additional route for the case where there is no path: