1

I have batch_class model, and under that articles, assignments resources are there. The routes.rb look like this.

resources :batch_classes do
  member do 
    resources :articles, except: [:index] 
    resources :assignments
 end

end

The problem is I am not getting desired URL route. My rake routes for edit assignments shows this.

/batch_classes/:id/assignments/:id/edit(.:format)

with alias name of edit_assignment_path. However, my expected route is

/batch_classes/:batch_class_id/assignments/:id/edit(.:format).

Please help.

Imran Ahmad
  • 2,798
  • 3
  • 28
  • 49
Rajan Verma - Aarvy
  • 1,969
  • 18
  • 20

2 Answers2

3

You can have nested routes by just putting nested resource inside parent resources.

resources :batch_classes do
  resources :assignments
end

Then, you surely will have a route called edit_batch_class_assignment_path and you can pass in instances as edit_batch_class_assignment_path(@batch_class, @assignment)

quyetdc
  • 1,485
  • 1
  • 14
  • 24
1

The desired path route can be achieved by taking resources :assignments out of the member block.

resources :batch_classes do
  resources :assignments
  member do 
    #...
  end
end

Going through this document is highly recommended for correct implementation.

Imran Ahmad
  • 2,798
  • 3
  • 28
  • 49