3

我正在关注 Michael Hartl 的 rails 教程。一切正常,但是当我在命令行上运行“rails server”时,出现以下错误:

=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-    3.2.13/lib/action_dispatch/routing/mapper.rb:254:in `merge': can't convert String into Hash (TypeError)
from /home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:254:in `root'
from /home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:1321:in `root'
from /home/jonathan/Desktop/railsTut/sample_app/config/routes.rb:4:in `block in <top (required)>'
from /home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in `instance_exec'
from /home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in `eval_block'
from /home/jonathan/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:267:in `draw'
from /home/jonathan/Desktop/railsTut/sample_app/config/routes.rb:1:in `<top (required)>'
.
.
.

这是我的 routes.rb 文件

SampleApp::Application.routes.draw do
  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  root  'static_pages#home'
  match '/signup',  to: 'users#new',            via: 'get'
  match '/signin',  to: 'sessions#new',         via: 'get'
  match '/signout', to: 'sessions#destroy',     via: 'delete'
  match '/help', to: 'static_pages#help'
  match '/about', to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact'

 end

任何帮助表示赞赏。

4

2 回答 2

3

尝试这个:

root to: 'static_pages#home'
于 2013-12-26T13:37:44.877 回答
3

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

root to: 'static_pages#home'

发生错误是因为,正如您在此处看到的,root方法期望它的参数是Hash在您传递时String

于 2013-07-19T08:05:20.850 回答