我正在编写 Sixrevision.com 教程“如何使用 Ruby on Rails 从头开始创建博客”。我尝试将它从 rails 2.x 转换为 3.x。当我运行 localhost:3000 我得到这个:
Routing Error
uninitialized constant PostController
Try running rake routes for more information on available routes.
Rake Routes 向我展示了这一点:
posts GET /posts(.:format) posts#index {:has_many=>:comments}
POST /posts(.:format) posts#create {:has_many=>:comments}
new_post GET /posts/new(.:format) posts#new {:has_many=>:comments}
edit_post GET /posts/:id/edit(.:format) posts#edit {:has_many=>:comments}
post GET /posts/:id(.:format) posts#show {:has_many=>:comments}
PUT /posts/:id(.:format) posts#update {:has_many=>:comments}
DELETE /posts/:id(.:format) posts#destroy {:has_many=>:comments}
/:controller/:action/:id(.:format) :controller#:action
/:controller/:action/:id.:format :controller#:action
root / post#index
我的 routes.rb 文件:
Myblog::Application.routes.draw do
resources :posts, :has_many => :comments
match ':controller/:action/:id'
match ':controller/:action/:id.:format'
root :to => "post#index"
end
有人知道吗?感谢您的关注和帮助!