2013-07-19 148 views
3

我遵循Michael Hartl的rails教程。一切工作正常,但是當我運行在命令行中我得到以下錯誤的「軌道服務器」:運行rails服務器時出錯

=> 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/[email protected]/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/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:254:in `root' 
from /home/jonathan/.rvm/gems/[email protected]/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/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in `instance_exec' 
from /home/jonathan/.rvm/gems/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in `eval_block' 
from /home/jonathan/.rvm/gems/[email protected]/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 

任何幫助表示讚賞。

+0

正如你所看到的,錯誤指向你'配置/ routes.rb'文件的第四行。除非您顯示您的'routes.rb'文件的內容,否則我們將無法提供幫助。 –

+0

道歉 - 我剛剛發佈了它 – user2551533

回答

3

在你行routes.rb 4,你應該有:發生

root to: 'static_pages#home' 

此錯誤的原因,正如你看到的hereroot方法預計其參數爲Hash,而你是通過String

+3

看來,'root'static_pages#home''在Rails 4中很好,但在Rails 3.2中沒有。 – Mischa

+0

拯救了我的生命.. :-) –

3

試試這個:

root to: 'static_pages#home'