rails产生错误' show'路线

时间:2017-01-16 12:35:22

标签: ruby-on-rails routes

我有以下show功能:

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是错误的,因为显示一篇文章需要:id

1 个答案:

答案 0 :(得分:1)

resource :articles

应该是

resources :articles

但是你发现了resource方法的作用:)