I am using Rails 3.2
I want to have routing pretty much exactly like github, so:
root/(username)
root/(username)/(projectname)
root/(username)/(projectname)/issus
etc.
I am trying something like this:
resources :publishers do
resources :magazines do
resources :photos
end
end
But that gives routes like this:
/publishers/1/magazines/2/photos/3
A project I am looking at does the following which seems to work but does not seem to be for me.
resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do
member do
get "team"
get "wall"
get "graph"
get "files"
end
resources :wikis, :only => [:show, :edit, :destroy, :create] do
member do
get "history"
end
end
If you want to get rid of the id number (which is rails default) and use a name I suggest the FriendlyId gem.
watch this railscast http://railscasts.com/episodes/314-pretty-urls-with-friendlyid
and here is the github page https://github.com/norman/friendly_id
EDIT
This is the article I was looking for, I forgot I bookmarked it months ago. http://jasoncodes.com/posts/rails-3-nested-resource-slugs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With