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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With