I’m building a Rails application which lets users have like a personal folder where they can upload files or make another folders.
How could I make a route that could be simmilar to
/user/:id/files/:any_path
and matches routes like this
/user/2/files/some_folder/a_file.doc
You can try to match a custom route like this:
This route would match
/user/2/files/3or/user/2/files/long/path/to/3, settingparams[:any_path]to"3"or"long/path/to/3".Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route:
By requesting
"/foo/bar.json", your params[:pages] will be equals to"foo/bar"with the request format of JSON. If you want the old 3.0.x behavior back, you could supply:format => falselike this:If you want to make the format segment mandatory, so it cannot be omitted, you can supply
:format => truelike this:This info and more details you can find on Rails routing from the outside in