缺失:资源创建的id路由

Jam*_*mes 3 ruby ruby-on-rails

rake routes创建资源之后:文章说我应该得到:

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
Run Code Online (Sandbox Code Playgroud)

但是我的路线总是缺少那些: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
Run Code Online (Sandbox Code Playgroud)

小智 7

我想你已添加到路线:

resource :articles
Run Code Online (Sandbox Code Playgroud)

代替:

resources :article
Run Code Online (Sandbox Code Playgroud)

当您不必提供id识别资源时,将使用奇异资源.即:当您对当前用户的个人资料进行操作时:/profile