简体   繁体   English

WEBrick rails服务器(Psych :: SyntaxError)| lynda.com教程

[英]WEBrick rails server (Psych::SyntaxError) | lynda.com tutorial

I'm a total newbie with RoR, so please forgive my density on this topic. 我是RoR的新手,所以请原谅我对这个主题的密度。

I'm trying to start the WEBrick application server using the rails server command, but I get the following error when I run it in my app directory /Users/Grace/Sites/simple_cms 我正在尝试使用rails server命令启动WEBrick应用程序服务器,但是当我在我的app目录/ Users / Grace / Sites / simple_cms中运行它时出现以下错误

I'm running the following: 我正在运行以下内容:

Rails 3.2.13 Rails 3.2.13

ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0] ruby 2.0.0p0(2013-02-24修订版39474)[x86_64-darwin12.3.0]

OSX 10.8.3 OSX 10.8.3

Here's the error stack: 这是错误堆栈:

Grace$ rails server
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://localhost:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 18 column 3 (Psych::SyntaxError)
    from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
    from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:153:in `parse'
    from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:129:in `load'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/application/configuration.rb:115:in `database_configuration'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:78:in `block (2 levels) in <class:Railtie>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/base.rb:720:in `<top (required)>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Grace/Sites/simple_cms/config/environment.rb:5:in `<top (required)>'
    from /Users/Grace/Sites/simple_cms/config.ru:3:in `require'
    from /Users/Grace/Sites/simple_cms/config.ru:3:in `block in <main>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /Users/Grace/Sites/simple_cms/config.ru:in `new'
    from /Users/Grace/Sites/simple_cms/config.ru:in `<main>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

When I open up the psych.rb file I see this: 当我打开psych.rb文件时,我看到:

require 'psych.so'
require 'psych/nodes'
require 'psych/streaming'
require 'psych/visitors'
require 'psych/handler'
require 'psych/tree_builder'
require 'psych/parser'
require 'psych/omap'
require 'psych/set'
require 'psych/coder'
require 'psych/core_ext'
require 'psych/deprecated'
require 'psych/stream'
require 'psych/json/tree_builder'
require 'psych/json/stream'
require 'psych/handlers/document_stream'

###
# = Overview
#
# Psych is a YAML parser and emitter.
# Psych leverages libyaml [Home page: http://pyyaml.org/wiki/LibYAML]
# or [Git repo: https://github.com/zerotao/libyaml] for its YAML parsing

Please help! 请帮忙! Thank you :) 谢谢 :)

Go into the database.yml file in your new rails project (if this is Lynda.com, that means it's the simple_cms project). 进入新的rails项目中的database.yml文件(如果这是Lynda.com,这意味着它是simple_cms项目)。

Make sure the keys on the left are followed by a colon, then a space, like this: 确保左侧的键后跟冒号,然后是空格,如下所示:

password: secret_phrase

And not like this, with no space after the colon: 而不是这样,结肠后没有空格:

password:secret_phrase

I also had the same problem and even though the indentations and spacings were correct in the database.yml I was still getting the errors. 我也有同样的问题,即使数据库中的缩进和间距是正确的。我仍然得到错误。 In my case the indentations were incorrect in the corresponding lines in application.yml. 在我的情况下,application.yml中相应行中的缩进不正确。

Very good @Steel, but remove the space does not solve (increases the number of errors). 非常好@Steel,但删除空间不解决(增加错误的数量)。 But really this error indicates that the problem is in the database.yml. 但实际上这个错误表明问题出在database.yml中。

In my case I had two statements socket. 在我的情况下,我有两个语句套接字。

Indentation of the code is important. 缩进代码很重要。

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: xxx
  pool: 5
  username: xxx
  password: xxx
  socket: /socket_adress
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: xxx
  pool: 5
  username: xxx
  password: xxx
  socket: /socket_adress
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: xxx
  pool: 5
  username: xxx
  password: xxx
  socket: /socket_adress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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