gpt4 book ai didi

ruby-on-rails - 运行 rails server 时出错

转载 作者:行者123 更新时间:2023-12-04 06:22:21 25 4
gpt4 key购买 nike

我正在学习 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

感谢任何帮助。

最佳答案

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

root to: 'static_pages#home'

发生错误是因为,如您所见here , root 方法在您传递 String 时期望其参数为 Hash

关于ruby-on-rails - 运行 rails server 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17740966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com