0

我正在研究http://sixrevisions.com上的“如何使用 Ruby on Rails 从头开始​​创建博客” 。本教程是为 Rails 2.x 创建的。我试图让它在 Rails 3.x 上运行。. 当我运行服务器并运行 localhost:3000 时,会出现一些严重的路由错误:

    Called from: C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/ac
    tion_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

    Exiting
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing
    /mapper.rb:185:in `default_controller_and_action': missing :action (ArgumentError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:78:in `normalize_options!'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:61:in `initialize'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1304:in `new'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1304:in `add_route'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1284:in `decomposed_match'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1270:in `block in match'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1270:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1270:in `match'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:260:in `root'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/mapper.rb:1317:in `root'
    from D:/myblog/config/routes.rb:5:in `block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/route_set.rb:282:in `instance_exec'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/route_set.rb:282:in `eval_block'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dis
    patch/routing/route_set.rb:260:in `draw'
    from D:/myblog/config/routes.rb:1:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/dependencies.rb:245:in `load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/dependencies.rb:245:in `block in load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/dependencies.rb:245:in `load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:40:in `block in load_paths'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:40:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:40:in `load_paths'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:16:in `reload!'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:26:in `block in updater'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/file_update_checker.rb:78:in `call'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_
    support/file_update_checker.rb:78:in `execute'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/routes_reloader.rb:27:in `updater'
    from C:in `execute_if_updated'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation/finisher.rb:66:in `block in <module:Finisher>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initia
    lizable.rb:30:in `instance_exec'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initia
    lizable.rb:30:in `run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initia
    lizable.rb:55:in `block in run_initializers'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initia
    lizable.rb:54:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initia
    lizable.rb:54:in `run_initializers'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/applic
    ation.rb:136:in `initialize!'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/railti
    e/configurable.rb:30:in `method_missing'
    from D:/myblog/config/environment.rb:5:in `<top (required)>'
    from D:/myblog/config.ru:3:in `require'
    from D:/myblog/config.ru:3:in `block in <main>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:
    51:in `instance_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:
    51:in `initialize'
    from D:/myblog/config.ru:in `new'
    from D:/myblog/config.ru:in `<main>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:
    40:in `eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:
    40:in `parse_file'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:2
    00:in `app'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/comman
    ds/server.rb:46:in `app'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:3
    04:in `wrapped_app'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:2
    54:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/comman
    ds/server.rb:70:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/comman
    ds.rb:55:in `block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/comman
    ds.rb:50:in `tap'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/comman
    ds.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

当我运行 rake routes 时,它向我展示了这一点:

    rake aborted!
    missing :action
    D:/myblog/config/routes.rb:5:in `block in <top (required)>'
    D:/myblog/config/routes.rb:1:in `<top (required)>'
    C:in `execute_if_updated'
    D:/myblog/config/environment.rb:5:in `<top (required)>'
    Tasks: TOP => routes => environment
    (See full trace by running task with --trace)

我的 Routes.rb 文件:

     Myblog::Application.routes.draw do

        resources :posts, :has_many => :comments
        match ':controller/:action/:id'
        match ':controller/:action/:id.:format'
        root :to => "post"

    end

我知道它相当模糊,但我不知道如何更简单地显示它。感谢您的帮助和兴趣!

4

1 回答 1

2

您在根 url 中缺少一个操作,例如 root :to => "posts#index"

#index 是控制器动作

于 2013-02-12T23:03:38.717 回答