Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Resource Generates DELETE/PUT Routes Without :id Parameters #29143

Closed
kassiansun opened this issue May 19, 2017 · 3 comments
Closed

Nested Resource Generates DELETE/PUT Routes Without :id Parameters #29143

kassiansun opened this issue May 19, 2017 · 3 comments

Comments

@kassiansun
Copy link

Steps to reproduce

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.

Expected behavior

From offical guides http://guides.rubyonrails.org/routing.html#nested-resources, it should generates:

DELETE	/magazines/:magazine_id/ads/:id	ads#destroy

System configuration

Rails version: Rails 5.1.1

Ruby version: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

@sevenseacat
Copy link
Contributor

You've specified singular resources, using resource in your routes instead of resources. If you fix that up, it should be all good.

@kassiansun
Copy link
Author

@sevenseacat Thank you! It's my mistake.

@williamromero
Copy link

That happened to me... 😜 Thank you for the answer because you helped me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants