Rails路由没有id

时间:2016-06-12 09:28:03

标签: ruby-on-rails routing

我向resource :products, :path => 'catalog/'添加了routes.rb,但我的溃败看起来像这样:

      products POST   /catalog(.:format)                            products#create
  new_products GET    /catalog/new(.:format)                        products#new
 edit_products GET    /catalog/edit(.:format)                       products#edit
               GET    /catalog(.:format)                            products#show
               PATCH  /catalog(.:format)                            products#update
               PUT    /catalog(.:format)                            products#update
               DELETE /catalog(.:format)                            products#destroy

为什么他们没有:id?例如,product#show应该有URI /products/:id(.:format),对吗?

此外,= link_to products_path(product), class: 'product' do会将我引导至http://localhost:3000/catalog.1

1 个答案:

答案 0 :(得分:3)

您应该使用resources :products代替resource :proucts。有关详细信息:https://cbabhusal.wordpress.com/2015/10/21/rails-routes-difference-between-resource-and-resources-in-routes-rb/