2017-01-16 86 views
0

我有以下顯示功能:軌道產生錯誤的 '秀' 路線

def show 
    @article = Article.find(params[:id]) 
end 

我的routes.rb看起來是這樣的:

resource :articles 

但是當我運行rake routes,我得到這個輸出:

 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 / 

您可以看到文章#show route is wrong,因爲需要:id才能顯示單曲e文章。

回答

1
resource :articles 

應該

resources :articles 

但是你已經發現resource方法做什麼:)