“rails server”不起作用。 “学习Rails”电子书第12章

时间:2013-12-04 22:49:04

标签: ruby-on-rails ruby ruby-on-rails-4 rvm

我正在阅读“学习Rails”一书,当我尝试使用我的Gmail帐户配置邮件程序时。我完成了第12章,并尝试启动服务器应用程序:

$ rails server

我收到了这个错误:

/Users/romenig/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): mapping values are not allowed in this context at line 6 column 15 (Psych::SyntaxError)
    from /Users/romenig/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
    from /Users/romenig/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:153:in `parse'
    from /Users/romenig/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:129:in `load'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/figaro-0.7.0/lib/figaro.rb:21:in `raw'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/figaro-0.7.0/lib/figaro.rb:17:in `env'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/figaro-0.7.0/lib/figaro/railtie.rb:7:in `block in <class:Railtie>'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:36:in `call'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/railties-4.0.1/lib/rails/application.rb:67:in `inherited'
    from /Users/romenig/workspace_ror/learn-rails/config/application.rb:10:in `<module:LearnRails>'
    from /Users/romenig/workspace_ror/learn-rails/config/application.rb:9:in `<top (required)>'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/railties-4.0.1/lib/rails/commands.rb:74:in `require'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/railties-4.0.1/lib/rails/commands.rb:74:in `block in <top (required)>'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
    from /Users/romenig/.rvm/gems/ruby-2.0.0-p353@learn-rails/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我需要做什么?

我搜索StackOverflow的类似问题,我建议安装“libyaml”:

$ rvm pkg install libyaml 

我收到了这条消息:

Beware, 'rvm pkg ...' is deprecated, read about the new autolibs feature: 'rvm help autolibs'.

Checking requirements for osx.
Updating certificates in '/opt/local/etc/openssl/cert.pem'.
romenig password required for 'mv -f /var/folders/y1/dgbv_pzd08bclqb3cnt_t0xw0000gn/T//tmp.ZRZBUpQ0BvThvcIhbV /opt/local/etc/openssl/cert.pem': 
Requirements installation successful.
Fetching yaml-0.1.4.tar.gz to /Users/romenig/.rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found
The requested url does not exist(22): 'https://rvm.io/src/yaml-0.1.4.tar.gz'
Checking fallback: ftp://rvm.io/src/yaml-0.1.4.tar.gz
Checking fallback: http://www.mirrorservice.org/sites/rvm.io/src/yaml-0.1.4.tar.gz
No fallback URL could be found, try increasing timeout with:

    echo "export rvm_max_time_flag=20" >> ~/.rvmrc


Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

我做了:

$ rvm reinstall all --force

当我这样做时,我看到了许多错误:

ruby-1.9.2-head - #compiling..............................................................................................
Error running '__rvm_make -j 1',
please read /Users/romenig/.rvm/log/1386193970_ruby-1.9.2-head/make.log
There has been an error while running make. Halting the installation.
Removing /Users/romenig/.rvm/src/ruby-2.0.0-p353
Removing /Users/romenig/.rvm/rubies/ruby-2.0.0-p353.................
Error running '__rvm_rm_rf /Users/romenig/.rvm/rubies/ruby-2.0.0-p353',
please read /Users/romenig/.rvm/log/1386194140_ruby-2.0.0-p353/remove.rubies.log
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.9/x86_64/ruby-2.0.0-p353.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/opt/local/etc/openssl/cert.pem' already are up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/romenig/.rvm/rubies/ruby-2.0.0-p353, this may take a while depending on your cpu(s)...
ruby-2.0.0-p353 - #downloading ruby-2.0.0-p353, this may take a while depending on your connection...
ruby-2.0.0-p353 - #extracting ruby-2.0.0-p353 to /Users/romenig/.rvm/src/ruby-2.0.0-p353
ruby-2.0.0-p353 - #extracted to /Users/romenig/.rvm/src/ruby-2.0.0-p353
ruby-2.0.0-p353 - #configuring.......
.........
Error running '__rvm_rm_rf /Users/romenig/.rvm/rubies/ruby-2.0.0-p353',
please read /Users/romenig/.rvm/log/1386194140_ruby-2.0.0-p353/remove.rubies.log
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.9/x86_64/ruby-2.0.0-p353.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/opt/local/etc/openssl/cert.pem' already are up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/romenig/.rvm/rubies/ruby-2.0.0-p353, this may take a while depending on your cpu(s)...
ruby-2.0.0-p353 - #downloading ruby-2.0.0-p353, this may take a while depending on your connection...
ruby-2.0.0-p353 - #extracting ruby-2.0.0-p353 to /Users/romenig/.rvm/src/ruby-2.0.0-p353
ruby-2.0.0-p353 - #extracted to /Users/romenig/.rvm/src/ruby-2.0.0-p353
ruby-2.0.0-p353 - #configuring.......

我试图再次启动Rails服务器:

$ rails server

得到了:

Rails is not currently installed on this system. To get the latest version, simply type:

$ sudo gem install rails

我再次安装了Rails并遇到了同样的错误。

2 个答案:

答案 0 :(得分:2)

首先,重新安装你所有的红宝石,你已经安装了宝石;但那些很容易回来。

cd进入项目目录并运行:

gem install bundler
bundle install

从原始错误消息:

mapping values are not allowed in this context at line 6 column 15 (Psych::SyntaxError)

看起来YAML文件中的语法存在问题。从堆栈跟踪看起来它来自Figaro,因此double-check来自config/application.yml文件。

答案 1 :(得分:0)

我的错误原因是 application.yml 中的以下行被拆分为两个,并且在注释范围之外 -

  

#Each entry设置一个本地环境变量并覆盖Unix中的ENV变量   外壳