Rails routing as github

I am using Rails 3.2

I want to have routing just like github, so:

root/(username)
root/(username)/(projectname)
root/(username)/(projectname)/issus

and etc.

I am trying something like this:

resources :publishers do
  resources :magazines do
    resources :photos
  end
end 

But it gives such routes:

/publishers/1/magazines/2/photos/3

The project I'm looking at does the following, which seems to work, but doesn't 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
+5
source share
2 answers

If you want to get rid of the ID number (which is the default rail) and use the 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

, , , . http://jasoncodes.com/posts/rails-3-nested-resource-slugs

+4

friendly_id

scope '/:username/:projectname', module: 'users/projects', as: 'users_project' do
    resources :issus
    resources :photos
end
0

All Articles