运行rails服务器时出错

时间:2013-07-19 07:59:26

标签: ruby-on-rails railstutorial.org

我正在关注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

感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

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

root to: 'static_pages#home'

发生错误的原因是,正如您here {{3}}所示,root方法在传递Hash时期望其参数为String

答案 1 :(得分:3)

试试这个:

root to: 'static_pages#home'