0

我正在编写 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

有人知道吗?感谢您的关注和帮助!

4

2 回答 2

2

routes.rb文件中:

resources :posts do
  resources :comments
end
于 2013-02-12T23:28:49.357 回答
0

在您的 routes.rb 中,您应该有:

root :to => 'posts#index'

因为你没有(可能) PostController 但 PostsController

于 2013-02-12T23:27:43.890 回答