Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails routing like github

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
like image 791
Jonovono Avatar asked Oct 07 '22 05:10

Jonovono


1 Answers

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

like image 129
Kyle C Avatar answered Oct 12 '22 22:10

Kyle C