Skip to content

Instantly share code, notes, and snippets.

@adamkleingit
Created June 17, 2013 20:52
Show Gist options
  • Save adamkleingit/5800283 to your computer and use it in GitHub Desktop.
Save adamkleingit/5800283 to your computer and use it in GitHub Desktop.
Routes for STI models
# If you want url_for(CoolProject) to give you 'cool_projects/1' but still go to ProjectsController then:
resources :cool_projects, :controller => :projects
# If you want url_for(CoolProject) to give you 'projects/1' and also go to ProjectsController then:
resources :cool_projects, :controller => :projects, :as => :projects
# If you want to reuse stuff inside resources:
projects_inner = lambda do
member do
resources :submodels
end
end
resources :cool_projects, :controller => :projects, :as => :projects, &projects_inner
resources :projects, &projects_inner
# If you want to pass a parameter of type then:
resources :cool_projects, :controller => :projects, :as => :projects, :type => 'CoolProject', &projects_inner
resources :projects, :type => 'Project', &projects_inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment