I would like to do something like github has with nested urls, and like How do I route user profile URLs to skip the controller? but not really sure how to go on with it.
For example, looking at a commit they have: ‘:user/:repo/commit/:sha’, with the controller being commit. How would I replicate this type of nested resource?
thank you 🙂
If commit is a RESTful controller that uses :sha instead of an id to find records. You could do this instead:
It will create the standard RESTful routes that look like
http://yoursite.tld/:user/:repo/commit/:idAgain, if you’ll never be translating the id portion in the url to a commit id, then there’s no reason you can’t use it as a :sha value.
example:
You may also want to over ride to_param in the commit model to return the sha value.
So that now
link_to commit_url(@commit, :user => current_user, :repo => @repo)will provide a url that matches your scheme.