Scaffolding with deep-nested routes

Viewed 5436

So I have a project that has routes as such:

routes.rb

resources :projects do
  resources :messages

  resources :lists do
    resources :tasks
  end
end

However, I want to add in time tracking for each task that I create, turning my routing into:

routes.rb

resources :projects do
  resources :messages

  resources :lists do
    resources :tasks do
      resources :timetracks
    end
  end
end

I want to scaffold the basics of my MVC and then go in and make necessary changes or edits, but how do I scaffold so that my controllers and views conform with my routing? Or is that even possible?


To elaborate further, when I typed this into the console:

rails generate scaffold timetrack hours:float date:datetime description:string task:references

I get the normal scaffolding files, but all of the routes are formatted as such:

http://localhost:3000/timetracks/

When really, I would like them to be:

http://localhost:3000/projects/1/lists/1/tasks/1/timetracks/

I know you can do this manually in the controllers and views, but is there any way I can have this generate while performing my scaffolding?

1 Answers
Related