views:

33

answers:

2

G'day guys,

Having a bit of an issue with Rails routes, at the moment.

Have a top resource: /Customer/ which itself has only one /Quote/ resource

Quotes can have both first_resources and second_resources

which are collections of resources associated with the quotes

Building the route, though how do I nest multiple routes under a has_one route?

map.resources :customer, :has_one => :quote

how do I do?

quote.resources :first_resources
quote.resources :second_resources

by mapping them as sub-elements to the substructure?

Or would it be easier to manage the collection in a different way?

A: 

map.resources :customers, :has_one => :quote

map.resource :quote, :has_many => :first_resources

map.resource :quote, :has_many => :second_resouces

Sam
+1  A: 

for this, I would nest inside of a block:

map.resources :customers do |customer|
  customer.resource :quote do |quote|
    quote.resources :first_resources
    quote.resources :second_resources
  end
end

alternative syntax:

map.resources :customers do |customer|
  customer.resource :quote, :has_many => [:first_resources, :second_resources]
end

This would give you urls of

customers/:customer_id/quote/first_resources/:id
customers/:customer_id/quote
customers/:id

Or the way you provided I believe you would need to map plural quotes in order to be able to get to a specific quote if you don't want to nest

map.resources :customers, :has_one => :quote
map.resources :quotes, :has_many => [:first_resources, :second_resources]

that would give you urls of

customers/:customer_id/quote
customers/:id
quotes/:quote_id/first_resources/:id

I think the first one is what you are after. Hope this helps.

Resources: http://api.rubyonrails.org/classes/ActionController/Resources.html

Geoff Lanotte