我在这里关注入门教程:
http://guides.rubyonrails.org/getting_started.html
我的路线.rb
Blog::Application.routes.draw do
resources :posts
root to: "welcome#index"
end
使用“rake route”命令,我得到:
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
Rake路线,输出为:
lidong@lidong-VirtualBox:~/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
我也无法获得'apples #index'。
答案 0 :(得分:1)
这是因为在你的路线中你宣布了一个独特的资源:
resource :posts
你想做的是:
resources :posts
请参阅 singular resources &的文档。 plural resources 了解更多信息。