教程应用中的路由错误从rails 2.x转换为3.x.

时间:2013-02-12 23:22:42

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-2

我正在研究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

有人知道吗?感谢intrest&帮助!

2 个答案:

答案 0 :(得分:2)

routes.rb档案中:

resources :posts do
  resources :comments
end

答案 1 :(得分:0)

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

root :to => 'posts#index'

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