config/routes.rb
:
Rails.application.routes.draw do
resource :orders do
resource :order_items
end
end
rails routes
:
Prefix Verb URI Pattern Controller#Action
new_orders_order_items GET /orders/order_items/new(.:format) order_items#new
edit_orders_order_items GET /orders/order_items/edit(.:format) order_items#edit
orders_order_items GET /orders/order_items(.:format) order_items#show
PATCH /orders/order_items(.:format) order_items#update
PUT /orders/order_items(.:format) order_items#update
DELETE /orders/order_items(.:format) order_items#destroy
POST /orders/order_items(.:format) order_items#create
new_orders GET /orders/new(.:format) orders#new
edit_orders GET /orders/edit(.:format) orders#edit
orders GET /orders(.:format) orders#show
PATCH /orders(.:format) orders#update
PUT /orders(.:format) orders#update
DELETE /orders(.:format) orders#destroy
POST /orders(.:format) orders#create
Test project is generated by rails new testa --database=postgresql --skip-system-test --skip-bundle --skip-coffee --skip-puma --skip-yarn
.
From offical guides http://guides.rubyonrails.org/routing.html#nested-resources, it should generates:
DELETE /magazines/:magazine_id/ads/:id ads#destroy
Rails version: Rails 5.1.1
Ruby version: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
You've specified singular resources, using resource
in your routes instead of resources
. If you fix that up, it should be all good.
@sevenseacat Thank you! It's my mistake.
That happened to me... 馃槣 Thank you for the answer because you helped me too.
Most helpful comment
You've specified singular resources, using
resource
in your routes instead ofresources
. If you fix that up, it should be all good.