Nested routing - ruby-on-rails

How do I write a route that maps a path like this?
/powerusers/bob/article-title
This is what I got so far:
map.resources :users, :as => "powerusers" do |users|
users.resources :articles, :as => ''
end
This gives me the following route:
/powerusers/:user_id//:id
How do I get rid of the double backslah? /powerusers/admin//first-article?
Best regards.
Asbjørn Morell

Ok, if you don't want the intermediate nested resource (/articles) I wouldn't use the map.resources at all.
Try:
map.connect '/powerusers/:user_id/:article_title', :controller => 'articles', :action => 'view_by_title'

If I add...
map.resources :users, :as => "powerusers" do |users|
users.resources :entries, :as => 'article-title'
end
I get the routes below, which include the one you want...
(Substitute "articles" for "entries" for your situation.)
GET /powerusers(.:format) {:controller=>"users", :action=>"index"}
POST /powerusers(.:format) {:controller=>"users", :action=>"create"}
GET /powerusers/new(.:format) {:controller=>"users", :action=>"new"}
GET /powerusers/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
GET /powerusers/:id(.:format) {:controller=>"users", :action=>"show"}
PUT /powerusers/:id(.:format) {:controller=>"users", :action=>"update"}
DELETE /powerusers/:id(.:format) {:controller=>"users", :action=>"destroy"}
user_entries GET /powerusers/:user_id/article-title(.:format) {:controller=>"entries", :action=>"index"}
POST /powerusers/:user_id/article-title(.:format) {:controller=>"entries", :action=>"create"}
new_user_entry GET /powerusers/:user_id/article-title/new(.:format) {:controller=>"entries", :action=>"new"}
edit_user_entry GET /powerusers/:user_id/article-title/:id/edit(.:format) {:controller=>"entries", :action=>"edit"}
user_entry GET /powerusers/:user_id/article-title/:id(.:format) {:controller=>"entries", :action=>"show"}
PUT /powerusers/:user_id/article-title/:id(.:format) {:controller=>"entries", :action=>"update"}
DELETE /powerusers/:user_id/article-title/:id(.:format) {:controller=>"entries", :action=>"destroy"}

Instead of nesting, would this work?
map.resources :users, :as => "powerusers"
map.resources :articles, :path_prefix => '/powerusers/:user_id'
I think it won't but a quick test would tell better :)

Related

Trouble Upgrading Rails 2 Routes for a Redmine Plugin

I am trying to get a Redmine plugin designed for Rails 2 to work with Rails 3.
https://github.com/dalyons/redmine-todos-scrum-plugin
I've pretty much fixed most parts, but having no success whatsoever in getting the routes to work.
The original routes for Rails 2 are as follows:
map.resources :todos, :name_prefix => 'project_', :path_prefix => '/projects/:project_id',
:member => {:toggle_complete => :post }, :collection => {:sort => :post}
map.resources :todos, :name_prefix => 'user_', :path_prefix => '/users/:user_id', :controller => :mytodos,
:member => {:toggle_complete => :post }, :collection => {:sort => :post}
map.my_todos 'my/todos', :controller => :mytodos, :action => :index
map.connect 'projects/:project_id/todos/show/:id', :controller => "todos", :action => "show"
rake routes outputs the following:
sort_project_todos POST /projects/:project_id/todos/sort(.:format) {:controller=>"todos", :action=>"sort"}
project_todos GET /projects/:project_id/todos(.:format) {:controller=>"todos", :action=>"index"}
POST /projects/:project_id/todos(.:format) {:controller=>"todos", :action=>"create"}
new_project_todo GET /projects/:project_id/todos/new(.:format) {:controller=>"todos", :action=>"new"}
toggle_complete_project_todo POST /projects/:project_id/todos/:id/toggle_complete(.:format) {:controller=>"todos", :action=>"toggle_complete"}
edit_project_todo GET /projects/:project_id/todos/:id/edit(.:format) {:controller=>"todos", :action=>"edit"}
project_todo GET /projects/:project_id/todos/:id(.:format) {:controller=>"todos", :action=>"show"}
PUT /projects/:project_id/todos/:id(.:format) {:controller=>"todos", :action=>"update"}
DELETE /projects/:project_id/todos/:id(.:format) {:controller=>"todos", :action=>"destroy"}
sort_user_todos POST /users/:user_id/todos/sort(.:format) {:controller=>"mytodos", :action=>"sort"}
user_todos GET /users/:user_id/todos(.:format) {:controller=>"mytodos", :action=>"index"}
POST /users/:user_id/todos(.:format) {:controller=>"mytodos", :action=>"create"}
new_user_todo GET /users/:user_id/todos/new(.:format) {:controller=>"mytodos", :action=>"new"}
toggle_complete_user_todo POST /users/:user_id/todos/:id/toggle_complete(.:format) {:controller=>"mytodos", :action=>"toggle_complete"}
edit_user_todo GET /users/:user_id/todos/:id/edit(.:format) {:controller=>"mytodos", :action=>"edit"}
user_todo GET /users/:user_id/todos/:id(.:format) {:controller=>"mytodos", :action=>"show"}
PUT /users/:user_id/todos/:id(.:format) {:controller=>"mytodos", :action=>"update"}
DELETE /users/:user_id/todos/:id(.:format) {:controller=>"mytodos", :action=>"destroy"}
my_todos /my/todos {:controller=>"mytodos", :action=>"index"}
/projects/:project_id/todos/show/:id {:controller=>"todos", :action=>"show"}
The nearest I have got for Rails 3 is as follows:
scope '/projects/:project_id', :name_prefix => 'project_' do
resources :todos, :controller => 'todos' do
member do
post :toggle_complete
end
collection do
post :sort
end
end
end
scope '/users/:user_id', :name_prefix => 'user_' do
resources :todos, :controller => 'mytodos' do
member do
post :toggle_complete
end
collection do
post :sort
end
end
end
match 'my/todos' => 'mytodos#index', :as => :my_todos
match 'projects/:project_id/todos/show/:id' => 'todos#show'
rake routes outputs the following:
toggle_complete_todo POST /projects/:project_id/todos/:id/toggle_complete(.:format) todos#toggle_complete {:name_prefix=>"project_"}
sort_todos POST /projects/:project_id/todos/sort(.:format) todos#sort {:name_prefix=>"project_"}
todos GET /projects/:project_id/todos(.:format) todos#index {:name_prefix=>"project_"}
POST /projects/:project_id/todos(.:format) todos#create {:name_prefix=>"project_"}
new_todo GET /projects/:project_id/todos/new(.:format) todos#new {:name_prefix=>"project_"}
edit_todo GET /projects/:project_id/todos/:id/edit(.:format) todos#edit {:name_prefix=>"project_"}
todo GET /projects/:project_id/todos/:id(.:format) todos#show {:name_prefix=>"project_"}
PUT /projects/:project_id/todos/:id(.:format) todos#update {:name_prefix=>"project_"}
DELETE /projects/:project_id/todos/:id(.:format) todos#destroy {:name_prefix=>"project_"}
POST /users/:user_id/todos/:id/toggle_complete(.:format) mytodos#toggle_complete {:name_prefix=>"user_"}
POST /users/:user_id/todos/sort(.:format) mytodos#sort {:name_prefix=>"user_"}
GET /users/:user_id/todos(.:format) mytodos#index {:name_prefix=>"user_"}
POST /users/:user_id/todos(.:format) mytodos#create {:name_prefix=>"user_"}
GET /users/:user_id/todos/new(.:format) mytodos#new {:name_prefix=>"user_"}
GET /users/:user_id/todos/:id/edit(.:format) mytodos#edit {:name_prefix=>"user_"}
GET /users/:user_id/todos/:id(.:format) mytodos#show {:name_prefix=>"user_"}
PUT /users/:user_id/todos/:id(.:format) mytodos#update {:name_prefix=>"user_"}
DELETE /users/:user_id/todos/:id(.:format) mytodos#destroy {:name_prefix=>"user_"}
my_todos /my/todos(.:format) mytodos#index
/projects/:project_id/todos/show/:id(.:format) todos#show
I am guessing that I am not using :name_prefix correctly, resulting in duplicate paths which are then omitted.
Any help would be greatly appreciated.
EDIT
I'm not sure whether this is the best way, but the following routes are working with Rails 3:
scope '/projects/:project_id' do
resources :todos, :controller => 'todos', :as => 'project_todos' do
member do
post :toggle_complete
end
collection do
post :sort
end
end
end
scope '/users/:user_id' do
resources :todos, :controller => 'mytodos', :as => 'user_todos' do
member do
post :toggle_complete
end
collection do
post :sort
end
end
end
match 'my/todos' => 'mytodos#index', :as => :my_todos
match 'projects/:project_id/todos/show/:id' => 'todos#show'
I removed :name_prefix from the scope and added :as to resource.

custom route no routes match

During cucumber tests, I get the following error:
No route matches "/companies/29/update_owner"
I am not sure what I am doing wrong, but im sure its something stupid.
I have the following routes:
company_update_owner POST /companies/:company_id/update_owner(.:format) {:controller=>"companies", :action=>"update_owner"}
company_set_owner /companies/:company_id/set_owner(.:format) {:controller=>"companies", :action=>"set_owner"}
companies GET /companies(.:format) {:action=>"index", :controller=>"companies"}
POST /companies(.:format) {:action=>"create", :controller=>"companies"}
new_company GET /companies/new(.:format) {:action=>"new", :controller=>"companies"}
edit_company GET /companies/:id/edit(.:format) {:action=>"edit", :controller=>"companies"}
company GET /companies/:id(.:format) {:action=>"show", :controller=>"companies"}
PUT /companies/:id(.:format) {:action=>"update", :controller=>"companies"}
DELETE /companies/:id(.:format) {:action=>"destroy", :controller=>"companies"}
I have tried:
company_update_owner_path(:company_id => #company.id)
and
company_update_owner_path(#company)
update:
= form_for #company, :url => company_update_owner_path(:company_id => #company.id), :method => :put do |f|
Any help would be greatly appreciated.
Here is the code in routes.rb:
resources :companies do
match '/update_owner' => 'companies#update_owner', :as => :update_owner, :via => :post
match '/set_owner' => 'companies#set_owner', :as => :set_owner
end
you need to remove the ":method=>:put"
Your route is declared as a POST but you're doing a PUT in the form. Fix either the route or the form and you'll nail it.
Would leave this as a comment, but the fromatting gets jacked.
If you're not aware, you can also define those routes slightly differently, too:
resources :companies do
member do
post "update_owner"
get "set_owner"
end
end

Rails Functional test on a custom route

I have the following routes in my app:
GET /admin/comments(.:format) {:controller=>"admin/comments", :action=>"index"}
admin_comments POST /admin/comments(.:format) {:controller=>"admin/comments", :action=>"create"}
new_admin_comment GET /admin/comments/new(.:format) {:controller=>"admin/comments", :action=>"new"}
GET /admin/comments/:id(.:format) {:controller=>"admin/comments", :action=>"show"}
PUT /admin/comments/:id(.:format) {:controller=>"admin/comments", :action=>"update"}
admin_comment DELETE /admin/comments/:id(.:format) {:controller=>"admin/comments", :action=>"destroy"}
edit_admin_comment GET /admin/comments/:id/edit(.:format) {:controller=>"admin/comments", :action=>"edit"}
admin_approve_comment /admin/comments/approve/:id {:module=>"admin", :controller=>"admin/comments", :action=>"approve"}
admin_reject_comment /admin/comments/reject/:id {:module=>"admin", :controller=>"admin/comments", :action=>"reject"}
which is declared as:
namespace "admin" do
resources :comments
match '/comments/approve/:id' => 'comments#approve', :as => "approve_comment", :module => "admin"
match '/comments/reject/:id' => 'comments#reject', :as => "reject_comment", :module => "admin"
end
and a functional test like this:
context "a POST to :approve" do
setup do
comment = Factory(:comment)
sign_in Factory(:admin)
post :approve, :id => comment.id
end
should respond_with :success
end
However, when I run this I get:
test: a POST to :approve should respond with 200. (Admin::CommentsControllerTest):
ActionController::RoutingError: No route matches {:action=>"approve", :id=>339, :controller=>"admin/comments"}
What's wrong here? What stupid mistake am I making?
These routes look like member routes to me. So routing this way
namespace "admin" do
resources :comments do
member do
get :approve
get :reject
end
end
end
This will generate routes like /admin/comments/:id/approve . This is the rails way as far i know.
I think it's better to put match before resources. Because it's not check if it's good or not.

Nested routes in Rails with an alias

I have a primary model for my project, Place.rb with a places_controller, and I've currently got it exactly the way I want for the users end of my project. With a nested photos controller, review, etc.
I want now to create a management resource which is mostly just an alias for Places, with its own nested resources, some of them overlapping, some of them new.
I tried creating a new controller for it called Manage, but I'm having a hard time with routes. I'm not quite sure the hangup is, but I figure I'm doing something very wrong. I had little difficulty when I was using Places as controller to a real model and nesting other resources below it.
But for example trying to create a new record for a nested resource doesn't route correctly.
I can get a route path like new_manage_room_path(#place) for a link_to to work fine. But
for creating a New announcement in a form:
form_for manage_room_path(#place) doesn't work correctly given a valid id. I've tried many other combinations supplying the object and :url.
Should I avoid using a separate controller and just create an alias or what is the special routing for this purpose?
map.resources :manage, :collection => { :upcoming => [ :post, :get ], :pending => [ :post, :get ] } do |manage|
manage.resources :rooms
manage.resources :room_rates, :as => :rates
manage.resources :availables
manage.resources :manage_bookings, :as => :bookings
end
map.resources :places do |place|
place.resources :bookings
place.resources :photos, :collection => { :sort => :post }
place.resources :reviews, :only => [ :index, :show ]
end
manage_rooms GET /manage/:manage_id/rooms(.:format) {:controller=>"rooms", :action=>"index"}
POST /manage/:manage_id/rooms(.:format) {:controller=>"rooms", :action=>"create"}
new_manage_room GET /manage/:manage_id/rooms/new(.:format) {:controller=>"rooms", :action=>"new"}
edit_manage_room GET /manage/:manage_id/rooms/:id/edit(.:format) {:controller=>"rooms", :action=>"edit"}
manage_room GET /manage/:manage_id/rooms/:id(.:format) {:controller=>"rooms", :action=>"show"}
PUT /manage/:manage_id/rooms/:id(.:format) {:controller=>"rooms", :action=>"update"}
DELETE /manage/:manage_id/rooms/:id(.:format) {:controller=>"rooms", :action=>"destroy"}
manage_room_rates GET /manage/:manage_id/rates(.:format) {:controller=>"room_rates", :action=>"index"}
POST /manage/:manage_id/rates(.:format) {:controller=>"room_rates", :action=>"create"}
new_manage_room_rate GET /manage/:manage_id/rates/new(.:format) {:controller=>"room_rates", :action=>"new"}
edit_manage_room_rate GET /manage/:manage_id/rates/:id/edit(.:format) {:controller=>"room_rates", :action=>"edit"}
manage_room_rate GET /manage/:manage_id/rates/:id(.:format) {:controller=>"room_rates", :action=>"show"}
PUT /manage/:manage_id/rates/:id(.:format) {:controller=>"room_rates", :action=>"update"}
DELETE /manage/:manage_id/rates/:id(.:format) {:controller=>"room_rates", :action=>"destroy"}
manage_availables GET /manage/:manage_id/availables(.:format) {:controller=>"availables", :action=>"index"}
POST /manage/:manage_id/availables(.:format) {:controller=>"availables", :action=>"create"}
new_manage_available GET /manage/:manage_id/availables/new(.:format) {:controller=>"availables", :action=>"new"}
edit_manage_available GET /manage/:manage_id/availables/:id/edit(.:format) {:controller=>"availables", :action=>"edit"}
manage_available GET /manage/:manage_id/availables/:id(.:format) {:controller=>"availables", :action=>"show"}
PUT /manage/:manage_id/availables/:id(.:format) {:controller=>"availables", :action=>"update"}
DELETE /manage/:manage_id/availables/:id(.:format) {:controller=>"availables", :action=>"destroy"}
manage_manage_bookings GET /manage/:manage_id/bookings(.:format) {:controller=>"manage_bookings", :action=>"index"}
POST /manage/:manage_id/bookings(.:format) {:controller=>"manage_bookings", :action=>"create"}
new_manage_manage_booking GET /manage/:manage_id/bookings/new(.:format) {:controller=>"manage_bookings", :action=>"new"}
edit_manage_manage_booking GET /manage/:manage_id/bookings/:id/edit(.:format) {:controller=>"manage_bookings", :action=>"edit"}
manage_manage_booking GET /manage/:manage_id/bookings/:id(.:format) {:controller=>"manage_bookings", :action=>"show"}
PUT /manage/:manage_id/bookings/:id(.:format) {:controller=>"manage_bookings", :action=>"update"}
DELETE /manage/:manage_id/bookings/:id(.:format) {:controller=>"manage_bookings", :action=>"destroy"}
pending_manage POST /manage/pending(.:format) {:controller=>"manage", :action=>"pending"}
GET /manage/pending(.:format) {:controller=>"manage", :action=>"pending"}
upcoming_manage POST /manage/upcoming(.:format) {:controller=>"manage", :action=>"upcoming"}
GET /manage/upcoming(.:format) {:controller=>"manage", :action=>"upcoming"}
manage_index GET /manage(.:format) {:controller=>"manage", :action=>"index"}
POST /manage(.:format) {:controller=>"manage", :action=>"create"}
new_manage GET /manage/new(.:format) {:controller=>"manage", :action=>"new"}
edit_manage GET /manage/:id/edit(.:format) {:controller=>"manage", :action=>"edit"}
manage GET /manage/:id(.:format) {:controller=>"manage", :action=>"show"}
PUT /manage/:id(.:format) {:controller=>"manage", :action=>"update"}
DELETE /manage/:id(.:format) {:controller=>"manage", :action=>"destroy"}
Try:
<% form_for #new_room, :url => manage_rooms_path(#place) do |f| %>
or maybe it will work this way:
<% form_for manage_rooms_path(#place, #new_room) do |f| %>
#new_room is new instance of Room model, so in controller add:
#new_room = Room.new

Shallow nested Rails routing with :as

I want:
Every projectpart to belong to a
project.
Every solution to belong to a
projectart (and to a project through
that projectpart).
Every image to belong to a solution
(and to a project and a projectpart
through that solution.)
Every document to belong to a
solution (and to a project and a
projectpart through that solution.)
Every URL to be as short as simple as
possible.
Every case of "projectpart" to appear
as "part" in every URL. (I couldn't
call the model "part" on Heroku.)
Can anyone tell me why this...
ActionController::Routing::Routes.draw do |map|
map.resources :projects, :shallow => true do |project|
project.resources :projectparts do |part|
part.resources :solutions do |solution|
solution.resources :images
solution.resources :documents
end
end
end
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
...is leaving a whole bunch of cases of "projectpart" in my URLs...
steven-nobles-imac-200:drominay steven$ rake routes
(in /Users/steven/Drominay)
projects GET /projects {:controller=>"projects", :action=>"index"}
formatted_projects GET /projects.:format {:controller=>"projects", :action=>"index"}
POST /projects {:controller=>"projects", :action=>"create"}
POST /projects.:format {:controller=>"projects", :action=>"create"}
new_project GET /projects/new {:controller=>"projects", :action=>"new"}
formatted_new_project GET /projects/new.:format {:controller=>"projects", :action=>"new"}
edit_project GET /projects/:id/edit {:controller=>"projects", :action=>"edit"}
formatted_edit_project GET /projects/:id/edit.:format {:controller=>"projects", :action=>"edit"}
project GET /projects/:id {:controller=>"projects", :action=>"show"}
formatted_project GET /projects/:id.:format {:controller=>"projects", :action=>"show"}
PUT /projects/:id {:controller=>"projects", :action=>"update"}
PUT /projects/:id.:format {:controller=>"projects", :action=>"update"}
DELETE /projects/:id {:controller=>"projects", :action=>"destroy"}
DELETE /projects/:id.:format {:controller=>"projects", :action=>"destroy"}
project_projectparts GET /projects/:project_id/projectparts {:controller=>"projectparts", :action=>"index"}
formatted_project_projectparts GET /projects/:project_id/projectparts.:format {:controller=>"projectparts", :action=>"index"}
POST /projects/:project_id/projectparts {:controller=>"projectparts", :action=>"create"}
POST /projects/:project_id/projectparts.:format {:controller=>"projectparts", :action=>"create"}
new_project_projectpart GET /projects/:project_id/projectparts/new {:controller=>"projectparts", :action=>"new"}
formatted_new_project_projectpart GET /projects/:project_id/projectparts/new.:format {:controller=>"projectparts", :action=>"new"}
edit_projectpart GET /projectparts/:id/edit {:controller=>"projectparts", :action=>"edit"}
formatted_edit_projectpart GET /projectparts/:id/edit.:format {:controller=>"projectparts", :action=>"edit"}
projectpart GET /projectparts/:id {:controller=>"projectparts", :action=>"show"}
formatted_projectpart GET /projectparts/:id.:format {:controller=>"projectparts", :action=>"show"}
PUT /projectparts/:id {:controller=>"projectparts", :action=>"update"}
PUT /projectparts/:id.:format {:controller=>"projectparts", :action=>"update"}
DELETE /projectparts/:id {:controller=>"projectparts", :action=>"destroy"}
DELETE /projectparts/:id.:format {:controller=>"projectparts", :action=>"destroy"}
projectpart_solutions GET /projectparts/:projectpart_id/solutions {:controller=>"solutions", :action=>"index"}
formatted_projectpart_solutions GET /projectparts/:projectpart_id/solutions.:format {:controller=>"solutions", :action=>"index"}
POST /projectparts/:projectpart_id/solutions {:controller=>"solutions", :action=>"create"}
POST /projectparts/:projectpart_id/solutions.:format {:controller=>"solutions", :action=>"create"}
new_projectpart_solution GET /projectparts/:projectpart_id/solutions/new {:controller=>"solutions", :action=>"new"}
formatted_new_projectpart_solution GET /projectparts/:projectpart_id/solutions/new.:format {:controller=>"solutions", :action=>"new"}
edit_solution GET /solutions/:id/edit {:controller=>"solutions", :action=>"edit"}
formatted_edit_solution GET /solutions/:id/edit.:format {:controller=>"solutions", :action=>"edit"}
solution GET /solutions/:id {:controller=>"solutions", :action=>"show"}
formatted_solution GET /solutions/:id.:format {:controller=>"solutions", :action=>"show"}
PUT /solutions/:id {:controller=>"solutions", :action=>"update"}
PUT /solutions/:id.:format {:controller=>"solutions", :action=>"update"}
DELETE /solutions/:id {:controller=>"solutions", :action=>"destroy"}
DELETE /solutions/:id.:format {:controller=>"solutions", :action=>"destroy"}
solution_images GET /solutions/:solution_id/images {:controller=>"images", :action=>"index"}
formatted_solution_images GET /solutions/:solution_id/images.:format {:controller=>"images", :action=>"index"}
POST /solutions/:solution_id/images {:controller=>"images", :action=>"create"}
POST /solutions/:solution_id/images.:format {:controller=>"images", :action=>"create"}
new_solution_image GET /solutions/:solution_id/images/new {:controller=>"images", :action=>"new"}
formatted_new_solution_image GET /solutions/:solution_id/images/new.:format {:controller=>"images", :action=>"new"}
edit_image GET /images/:id/edit {:controller=>"images", :action=>"edit"}
formatted_edit_image GET /images/:id/edit.:format {:controller=>"images", :action=>"edit"}
image GET /images/:id {:controller=>"images", :action=>"show"}
formatted_image GET /images/:id.:format {:controller=>"images", :action=>"show"}
PUT /images/:id {:controller=>"images", :action=>"update"}
PUT /images/:id.:format {:controller=>"images", :action=>"update"}
DELETE /images/:id {:controller=>"images", :action=>"destroy"}
DELETE /images/:id.:format {:controller=>"images", :action=>"destroy"}
solution_documents GET /solutions/:solution_id/documents {:controller=>"documents", :action=>"index"}
formatted_solution_documents GET /solutions/:solution_id/documents.:format {:controller=>"documents", :action=>"index"}
POST /solutions/:solution_id/documents {:controller=>"documents", :action=>"create"}
POST /solutions/:solution_id/documents.:format {:controller=>"documents", :action=>"create"}
new_solution_document GET /solutions/:solution_id/documents/new {:controller=>"documents", :action=>"new"}
formatted_new_solution_document GET /solutions/:solution_id/documents/new.:format {:controller=>"documents", :action=>"new"}
edit_document GET /documents/:id/edit {:controller=>"documents", :action=>"edit"}
formatted_edit_document GET /documents/:id/edit.:format {:controller=>"documents", :action=>"edit"}
document GET /documents/:id {:controller=>"documents", :action=>"show"}
formatted_document GET /documents/:id.:format {:controller=>"documents", :action=>"show"}
PUT /documents/:id {:controller=>"documents", :action=>"update"}
PUT /documents/:id.:format {:controller=>"documents", :action=>"update"}
DELETE /documents/:id {:controller=>"documents", :action=>"destroy"}
DELETE /documents/:id.:format {:controller=>"documents", :action=>"destroy"}
/:controller/:action/:id
/:controller/:action/:id.:format
...and yet is not generating basic URL helpers, like this?
undefined method `project_projectpart_path' for #<ActionView::Base:0x3438ffc> (ActionView::TemplateError)
BTW, everything except changing "projectpart" to "part" in every URL was working fine with this more verbose syntax:
ActionController::Routing::Routes.draw do |map|
map.resources :projects, :has_many => :projectparts
map.resources :projects, :has_many => :solutions
map.resources :projects, :has_many => :images
map.resources :projects, :has_many => :documents
map.resources :projectparts, :has_many => :solutions
map.resources :projectparts, :has_many => :images
map.resources :projectparts, :has_many => :documents
map.resources :solutions, :has_many => :images
map.resources :solutions, :has_many => :documents
map.resources :images
map.resources :documents
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
The answer to your question about route generation is :shallow => true
Providing the shallow option will create longer routes for collection methods of the inner resource(s), while providing shallow routes for member methods of those nested resource(s). Take a closer look at the routes created and you'll see this.
Essentially routes that need an id (edit,update,show,destroy) will the short one containing only the inner most resource . Routes that don't need an id(index,new) will be slightly longer, containing the immediate parent.
You don't need project_projectpart_path because the project in project_projectpart can be implied from the project part. Instead just use projectpart_path for existing project parts.
Your second example provides those missing routes because it never gives the shallow option.
Changing 'projectpart' to 'part' in urls is as simple as adding the :as option in it's definition. Sorry it won't work with the shorthand :has_many version
map.resources :projects, :shallow => true do |project|
project.resources :projectparts, :as => "part" do |part|
part.resources :solutions do |solution|
solution.resources :images
solution.resources :documents
end
end
end

Resources