rails 4:在此上下文中,第2行第11列(Psych :: SyntaxError)不允许映射值?

问题描述 投票:5回答:3

我已经成功安装了rails 4并使用rails 4.0.0创建了项目

rails s

第一次工作正常。但是在gemfile中添加了“ devise” gem之后

 gem 'devise', '~> 3.0.0.rc'

并且正在运行捆绑软件安装,出现以下错误。该错误的原因是什么,将如何解决?

我也尝试在gem'devise'部分添加注释,但是现在我对每个rails命令都遇到相同的错误。

/home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse':   (<unknown>): mapping values are not allowed in this context at line 2 column 11 (Psych::SyntaxError)
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:153:in `parse'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:129:in `load'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/config_file.rb:318:in `load_file'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/config_file.rb:191:in `initialize'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/gem_runner.rb:66:in `new'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/gem_runner.rb:66:in `do_configuration'
from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/gem_runner.rb:46:in `run'

database.yml文件

development:
adapter: mysql2
encoding: utf8
database: realstate_development
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock

gem'devise'的任何版本,在捆绑软件上均显示以下错误,如果我删除devise gem可以正常工作,我使用的是rails 3.2.13,但我从未遇到过这样的问题,太奇怪了。

Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Unfortunately, a fatal error has occurred. Please see the Bundler troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): mapping values are not allowed in this context at line 2 column 11 (Psych::SyntaxError)
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:153:in `parse'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/psych.rb:129:in `load'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/config_file.rb:318:in `load_file'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/config_file.rb:191:in `initialize'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems.rb:319:in `new'
    from /home/siv/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems.rb:319:in `configuration'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:34:in `configuration'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:53:in `sources='
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:250:in `remote_specs'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:163:in `fetch_specs'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:67:in `specs'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:192:in `block (2 levels) in index'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `each'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `block in index'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/index.rb:9:in `build'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:185:in `index'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:179:in `resolve'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/definition.rb:109:in `resolve_remotely!'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/installer.rb:83:in `run'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/installer.rb:14:in `install'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/cli.rb:247:in `install'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/bin/bundle:20:in `block in <top (required)>'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/bin/bundle:20:in `<top (required)>'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/bin/bundle:23:in `load'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247@global/bin/bundle:23:in `<main>'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/siv/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
ruby-on-rails devise rubygems gem ruby-on-rails-4
3个回答
5
投票

如果有人仍然遇到相同的错误,则可以检查项目中的YAML文件。在此示例中,问题是database.yml中缺少缩进。它看起来应该像这样:

development:
  adapter: mysql2
  encoding: utf8
  database: realstate_development
  pool: 5
  username: root
  password: root
  socket: /var/run/mysqld/mysqld.sock

我遇到相同的错误,但基于其他原因,整个问题出在错误的application.yml


2
投票

首先请注意由于Psych :: SyntaxError而使解析方法失败的yml文件。然后在文件中查找以下内容

YAML文件应适当缩进,并且必须遵循正确的语法。 1。列表的所有成员都是以“-”(破折号和空格)开头的相同缩进级别的行:2。字典用简单的键表示:值形式(冒号后面必须有空格):有关语法的更多信息,请检查以下链接:http://docs.ansible.com/ansible/YAMLSyntax.html


0
投票

这里是一个可以清除您的yml的工具。http://www.yamllint.com/那可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.