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 Validatorを使用して 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

追加しようとしました:

host:localhost

追加する必要があったことがわかりました:

host: localhost

":" の後に 1 つのスペース

お役に立てれば

于 2015-04-28T05:37:24.507 に答える
0

にスペースの代わりにタブがあると思いますdatabase.yml

vimでのクイックフィックス:

:%s/\t/  /g
于 2013-10-18T06:07:43.030 に答える
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 に答える