我向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
答案 0 :(得分:3)
您应该使用resources :products
代替resource :proucts
。有关详细信息:https://cbabhusal.wordpress.com/2015/10/21/rails-routes-difference-between-resource-and-resources-in-routes-rb/