简体   繁体   中英

Error when running rails server

I am following Michael Hartl's rails tutorial. Everything was working fine, but when I run "rails server" on the command line I get the following error:

=> 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)>'
.
.
.

Here is my routes.rb file

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

Any help is appreciated.

In your line 4 of routes.rb you should have:

root to: 'static_pages#home'

The error occurs because, as you see here , root method expect its parameter to be Hash while you are passing String .

试试这个:

root to: 'static_pages#home'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM