2015-07-21 103 views
3

rake routes ID航线创建资源后:文章说我应该得到:缺少:在创建资源

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 
+0

您可以发布您的路线文件吗? – adamliesko

+3

确保您使用的是资源:文章,而不是资源:文章 –

回答

6

我猜你已经添加到路由:代替

resource :articles 

:当你没有提供id查明资源

resources :article 

奇异的资源使用。即:当您在当前用户的个人资料上操作时:/profile

+1

这是一个微妙的差异,初学者Rails开发人员会错过一些东西。 – wurde

+0

谢谢,它是一个令人尴尬的小变化,我不敢相信我从未接受过。 – James