2015-04-12 17 views
0

我想讓我的第一個Ror應用程序,這裏是我的第一個問題:)爲什麼我需要'show.html.erb'模板去'.../posts/index'?

當我到localhost:3000/posts/index,我得到消息'Missing template posts/show,application/show with { :locale ...'爲什麼是這樣?爲什麼我需要show.html.erb模板的posts/index?

routes.rb$rake routes命令文件

Rails.application.routes.draw do 
    resources :posts 
    root 'posts#index' 
end 

路線:

Prefix Verb URI Pattern   Controller#Action 
    posts GET /posts(.:format)   posts#index 
      POST /posts(.:format)   posts#create 
new_post GET /posts/new(.:format)  posts#new 
edit_post GET /posts/:id/edit(.:format) posts#edit 
    post GET /posts/:id(.:format)  posts#show 
      PATCH /posts/:id(.:format)  posts#update 
      PUT /posts/:id(.:format)  posts#update 
      DELETE /posts/:id(.:format)  posts#destroy 
    root GET /      posts#index 

回答

2

如果你檢查你的路線you'l會發現,帖子#index動作映射到/職位,而不是職位/指數。

這裏發生了什麼是/ posts/index正在將mappend映射到/ posts /:id,並將索引設置爲id。通過GET請求將其映射到show操作。

+0

謝謝James :) – Alek

相關問題