1

我有 ROR 版本 4.0.0 和 ruby​​ 版本 2.0.0。创建项目应用程序后,当我尝试运行 rails 服务器时,它向我显示有关 yml 文件的错误。画面长这样

    C:\Sites\app>rails s
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on 
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/ap
plication/configuration.rb:113:in `rescue in database_configuration': YAML synta
x error occurred while parsing C:/Sites/app/config/database.yml. Please note tha
t YAML must be consistently indented using spaces. Tabs are not allowed. Error:
(<unknown>): could not find expected ':' while scanning a simple key at line 9 c
olumn 3 (RuntimeError)
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0
/lib/rails/application/configuration.rb:103:in `database_configuration'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4
.0.0/lib/active_record/railtie.rb:174:in `block (2 levels) in <class:Railtie>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4
.0.0/lib/active_record/railtie.rb:173:in `block in <class:Railtie>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0
/lib/rails/initializable.rb:30:in `instance_exec'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0
/lib/rails/initializable.rb:30:in `run'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0
/lib/rails/initializable.rb:55:in `block in run_initializers'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block i
n tsort_each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (
2 levels) in each_strongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_st
rongly_connected_component_from'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block i
n each_strongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_st
rongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_e
ach'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0
/lib/rails/initializable.rb:54:in `run_initializers'

请帮助我。

4

4 回答 4

2

您可以使用某种YAML 验证器检查您的 YAML 文件

这是您的有效 YAML:

development: 
  adapter: postgresql
  database: postgres
  password: 191192
  pool: 5
  timeout: 5000
  username: postgres
production: 
  adapter: postgresql
  database: postgres
  pool: 5
  timeout: 5000
test: 
  adapter: postgresql
  database: postgres
  pool: 5
  timeout: 5000
于 2013-10-18T08:08:09.993 回答
0

如果您查看跟踪,它会准确地告诉您 database.yml 文件出了什么问题。

"Please note that YAML must be consistently indented using spaces. Tabs are not allowed."

"could not find expected ':' while scanning a simple key at line 9 column 3"

因此,请确保您使用的是空格,而不是制表符,并查看第 9 行是否缺少冒号。

于 2013-10-18T06:15:25.777 回答
0

我试图添加:

host:localhost

原来我应该添加:

host: localhost

“:”后加一个空格

希望这可以帮助

于 2015-04-28T05:37:24.507 回答
0

我的猜测是你的database.yml.

vim 中的快速修复:

:%s/\t/  /g
于 2013-10-18T06:07:43.030 回答