RESTful Routes Confusion

Hi All,

I’m working on a simple asset tracker application, but I’ve got a bit
confused about routes. Briefly, in my application there are users who
can have many assets, and each asset can have many incomings or
outgoings. In turn, each incoming or outgoing is assigned a category.
I’m using Edge Rails.

What I’d like to do is have every URL start with /users//
(e.g. /users/johntopley/assets/1). I know about :path_prefix and that
you can nest resources, but I haven’t been able to work out how to
achieve what I’m after.

This is my routes file:

ActionController::Routing::Routes.draw do |map|
map.home ‘’, :controller => ‘assets’, :action => ‘index’

map.resources :assets, :categories, :incomings, :outgoings, :users

map.signin ‘/signin’, :controller => ‘application’, :action =>
‘signin’
map.signout ‘/signout’, :controller => ‘application’, :action =>
‘signout’
map.signup ‘/signup’, :controller => ‘application’, :action =>
‘signup’

map.connect ‘:controller/:action/:id’
end

Any help would be greatly appreciated.

On 11/25/06, John T. [email protected] wrote:

(e.g. /users/johntopley/assets/1). I know about :path_prefix and that
you can nest resources, but I haven’t been able to work out how to
achieve what I’m after.

You need to nest the resources. It’ll look like this:

map.resources :users do |u|
u.resources :assets
end

I’m not too clear on what you meant by the incomings, outgoings, and
categories, but you can continue to nest things if that’s what you
need. Don’t know if this is what you’ll need, but it’s an example:

map.resources :users do |u|
u.resources :assets do |a|
a.resources :incomings, :outgoings, :categories
end
end