缺失:资源创建的id路由

时间:2015-07-21 12:51:32

标签: ruby-on-rails ruby

创建资源后我的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

然而,我的路线总是缺少那些:其中包含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

1 个答案:

答案 0 :(得分:6)

我猜你已添加到路线:

resource :articles

而不是:

resources :article

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