gpt4 book ai didi

ruby-on-rails - 缺少 :id routes on resource creation

转载 作者:数据小太阳 更新时间:2023-10-29 07:47:45 25 4
gpt4 key购买 nike

创建资源后我的 rake routes :articles 说我应该得到:

Prefix Verb      URI Pattern                  Controller#Action
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index

但是我的路线总是缺少那些带有 :id 的路线。

Prefix Verb   URI Pattern              Controller#Action
articles POST /articles(.:format) articles#create
new_articles GET /articles/new(.:format) articles#new
edit_articles GET /articles/edit(.:format) articles#edit
GET /articles(.:format) articles#show
PATCH /articles(.:format) articles#update
PUT /articles(.:format) articles#update
DELETE /articles(.:format) articles#destroy
root GET / welcome#index

最佳答案

我猜你已经添加到路由中了:

resource :articles

代替:

resources :article

当您不必提供 id 来识别资源时,使用单一资源。即:当你对当前用户的个人资料进行操作时:/profile

关于ruby-on-rails - 缺少 :id routes on resource creation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31539547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com