YAML 文件中的 Rails 语法错误?

发布于 2024-11-28 16:40:31 字数 6779 浏览 4 评论 0原文

为什么我在运行 rails console 时收到以下错误?

NOTE: Gem.available? is deprecated, use Specification::find_by_name. It will be removed on or after 2011-11-01.
Gem.available? called from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/jasmine-1.0.2.1/lib/jasmine/base.rb:64.
syntax error on line 1, col 1: `:'
/Users/Chetan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/Chetan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:151:in `initialize'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new_instance'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:8:in `instance'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/newrelic_rpm.rb:36:in `block in <class:Railtie>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `instance_exec'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `run'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:50:in `block in run_initializers'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `each'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `run_initializers'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:92:in `initialize!'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/Chetan/Development/othermind/config/environment.rb:5:in `<top (required)>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `block in require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:78:in `require_environment!'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/commands.rb:39:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:156:in `rescue in initialize': Error reading newrelic.yml file: syntax error on line 1, col 1: `:' (RuntimeError)
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:139:in `initialize'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new_instance'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:8:in `instance'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/newrelic_rpm.rb:36:in `block in <class:Railtie>'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `run'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `each'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:92:in `initialize!'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Chetan/Development/othermind/config/environment.rb:5:in `<top (required)>'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `block in require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:78:in `require_environment!'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

有问题的 newrelic.yml 文件(来自本指南的 Cedar 部分):

---
<%= ENV["RAILS_ENV"] %>:
  error_collector:
    capture_source: true
    enabled: true
    ignore_errors: ActionController::RoutingError
  apdex_t: 0.5
  ssl: false
  monitor_mode: true
  license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %>
  developer_mode: false
  app_name: <%= ENV["NEW_RELIC_APPNAME"] %>
  transaction_tracer:
    record_sql: obfuscated
    enabled: true
    stack_trace_threshold: 0.5
    transaction_threshold: apdex_f
  capture_params: false
  log_level: info

它解析很好 http://yaml-online-parser.appspot.com/...

Why am I getting the following error when I run rails console?

NOTE: Gem.available? is deprecated, use Specification::find_by_name. It will be removed on or after 2011-11-01.
Gem.available? called from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/jasmine-1.0.2.1/lib/jasmine/base.rb:64.
syntax error on line 1, col 1: `:'
/Users/Chetan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/Chetan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in `load'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:151:in `initialize'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new_instance'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:8:in `instance'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/newrelic_rpm.rb:36:in `block in <class:Railtie>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `instance_exec'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `run'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:50:in `block in run_initializers'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `each'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `run_initializers'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:92:in `initialize!'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/Chetan/Development/othermind/config/environment.rb:5:in `<top (required)>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `block in require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:78:in `require_environment!'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/commands.rb:39:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
/Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:156:in `rescue in initialize': Error reading newrelic.yml file: syntax error on line 1, col 1: `:' (RuntimeError)
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/instance_methods.rb:139:in `initialize'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:21:in `new_instance'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/new_relic/control/class_methods.rb:8:in `instance'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/newrelic_rpm-3.1.1/lib/newrelic_rpm.rb:36:in `block in <class:Railtie>'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `run'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `each'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:92:in `initialize!'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Chetan/Development/othermind/config/environment.rb:5:in `<top (required)>'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `block in require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/application.rb:78:in `require_environment!'
    from /Users/Chetan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0.rc5/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

The newrelic.yml file in question (from the Cedar section of this guide):

---
<%= ENV["RAILS_ENV"] %>:
  error_collector:
    capture_source: true
    enabled: true
    ignore_errors: ActionController::RoutingError
  apdex_t: 0.5
  ssl: false
  monitor_mode: true
  license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %>
  developer_mode: false
  app_name: <%= ENV["NEW_RELIC_APPNAME"] %>
  transaction_tracer:
    record_sql: obfuscated
    enabled: true
    stack_trace_threshold: 0.5
    transaction_threshold: apdex_f
  capture_params: false
  log_level: info

It parses fine with http://yaml-online-parser.appspot.com/...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

颜漓半夏 2024-12-05 16:40:31

您的错误消息表明 <%= ENV["RAILS_ENV"] %> 为空,因此 YAML 的第一行只是一个冒号,这不是很有用。

我猜您正在使用 Rails 3 并且 ENV['RAILS_ENV'] 不再可用(注意:我知道它不在 3.1 中,但我不确定 3.0) 。尝试使用这个:

<%= Rails.env %>:

相反,Rails.env 应该在您可能使用的任何 Rails 版本中可用。如果这不起作用,您可以尝试直接进入:

production:

因为无论如何这可能就是您的 Heroku 环境。

Your error message indicates that <%= ENV["RAILS_ENV"] %> is coming up empty so the first line of your YAML is just a single colon and that's not very useful.

I'd guess that you're using Rails 3 and ENV['RAILS_ENV'] is no longer available (note: I know it isn't around in 3.1 but I'm not certain about 3.0). Try using this:

<%= Rails.env %>:

instead, Rails.env should be available in any Rails versions that you're likely to be using. And if that doesn't work, you can try going straight to:

production:

since that will probably be your Heroku environment anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文