Tomer Lichtash
Tomer Lichtash

Reputation: 9262

How to create a second level route in Rails?

I'm trying to get the following spec to work. So far I've had some success with making both of these cases work:

But how do I get User/Project/Tasks to list all the tasks in the Project (all tasks in project, not just the user's tasks in the project)?

My routes.rb is as following:

resources :users do
  resources :tasks, :through => :projects
  resources :projects
end

Upvotes: 0

Views: 83

Answers (1)

Andy Lindeman
Andy Lindeman

Reputation: 12165

Can it not simply be accomplished with?

resources :users do
  resources :projects do
    resources :tasks
  end
end

Feel free to keep the other route for :tasks around .. you'll just have to handle which case it is in your TasksController.

Upvotes: 3

Related Questions