Carriles 3: Recursos anidados ¿3 niveles de profundidad?

he leído este artículo by James Buck, but it's a bit out of date.

Here's what I know is considered bad practice:

resources :companies do
  resources :users
  resources :roles
  resources :people do
    resources :notes
  end
end

Is this what I should be doing?

resources :companies do
  resources :users, :roles, :people
end

resources :people do
  resources :notes
end

And can someone please explain to me why or why not?

preguntado el 01 de febrero de 12 a las 04:02

yes, that's the essence of it. -

1 Respuestas

Both will generate the exact routes for :companies , :users , :roles and for :people .

But :notes route will differ .

In first case for the :notes route will generate something like :

/companies/:company_id/people/:person_id/notes(.:format) 
/companies/:company_id/people/:person_id/notes/new(.:format)

and in second case routes will not relate with companies , and looks like :

/people/:person_id/notes(.:format)
/people/:person_id/notes/new(.:format)

So I think its depend on your application and which routes you want to prefer .

Espero que esto ayude.

Respondido 01 Feb 12, 17:02

I understand that the routes will be different, but I'm more curious about what's considered best practice? I've read not to nest beyond two levels, so is my second example considered Best Practice? I'm new to Rails and want to start off on the right foot. - Spencer Fry

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.