2014-01-23 17 views
0

我下面的入門教程在這裏:Rails的「入門」的路線:不能拿到 「上崗#指數」

http://guides.rubyonrails.org/getting_started.html

我route.rb

Blog::Application.routes.draw do 

    resources :posts 

    root to: "welcome#index" 
end 

隨着命令「耙路線」,我得到:

  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  /      welcome#index 

我無法找到一個途徑" posts GET /posts(.:format) posts#index"

我的rails版本是4.0.2。請有人給我一些幫助嗎?

我又增加了資源如下:

Blog::Application.routes.draw do 
# get "welcome/index" 

    resource :posts 
    resource :apples 


    root 'welcome#index' 

end 

耙路線,輸出爲:

[email protected]:~/blog$ rake routes 
    Prefix Verb URI Pattern   Controller#Action 
     posts POST /posts(.:format)  posts#create 
    new_posts GET /posts/new(.:format) posts#new 
edit_posts GET /posts/edit(.:format) posts#edit 
      GET /posts(.:format)  posts#show 
      PATCH /posts(.:format)  posts#update 
      PUT /posts(.:format)  posts#update 
      DELETE /posts(.:format)  posts#destroy 
    apples POST /apples(.:format)  apples#create 
new_apples GET /apples/new(.:format) apples#new 
edit_apples GET /apples/edit(.:format) apples#edit 
      GET /apples(.:format)  apples#show 
      PATCH /apples(.:format)  apples#update 
      PUT /apples(.:format)  apples#update 
      DELETE /apples(.:format)  apples#destroy 
     root GET /     welcome#index 

我也不能得到 '蘋果#指數'。

+1

您確定您正在粘貼命令的完整輸出嗎?指數行動應該在那裏。 – Agis

+0

啓動服務器並在瀏覽器中訪問'http:// localhost:3000/posts' – itsnikolay

+0

是的,我確定我粘貼了所有輸出。請參閱我的進一步測試。 – user3226757

回答

1

這是因爲在你的路由你宣佈一個單一的資源:

resource :posts 

你想幹什麼istead:

resources :posts 

參考文檔singular resources & plural resources爲更多信息。

+0

嗨,Agis,是的,你是對的,我犯了一個錯誤。非常感謝你! – user3226757

+0

@ user3226757不客氣。還不如*接受答案*如果它解決了你的問題(「勾號」圖標)。 – Agis