我有以下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
。
答案 0 :(得分:1)
resource :articles
应该是
resources :articles
但是你发现了resource
方法的作用:)