Question

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?

Was it helpful?

Solution

As far as I know, there is no way to create nested routes via the standard rails3 scaffolding, however, I did a quick search and came up with this gem: https://github.com/amatsuda/nested_scaffold

For reference, I found it via this similar question: Nested scaffold generator for Rails 3?

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top