This would involve changing FriendsController to People::
FriendsController and moving it to app/controllers/people/friends_controller.rb.
Then, the route declaration should be changed to:
map.resources :people do |person|
person.resources :friends, :controller => 'people/friends',
:name_prefix => 'person_'
end
The name_prefix option adds a prefix to the generated routes. In this case, adding
that option to the person.resources line gives us named routes like person_friends_
path and person_friend_path instead of friends_path and friend_path, which better
reflects the new scoping of our resources.
There is a path_prefix option that will add a prefix to the URIs that the route will
recognize and generate. This comes with nested routes??”you don??™t have to do anything.
The nested routes above could be manually specified as follows:
map.resources :people
map.resources :friends, :controller => 'people/friends',
:name_prefix => 'person_',
:path_prefix => '/people/:person_id'
This usage is not as pretty, but it affords more control over the parameter names
your controller is passed. This method makes more sense if the IDs being used in the
routes are something other than ActiveRecord numeric primary keys.
Singleton resource routes
Sometimes, there will be an entity that exists as a singleton, such that there will only
be one in existence within its containing scope.
Pages:
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338