刚刚升级到 Rails 4.1 并且正在使用secrets.yml
.
这是它的样子:
development:
secret_key_base: akshdakjshdgakjhsdgakjdhgaskjdhgaskjdhgska
test:
secret_key_base: somelegitlongasskeygeneratedbyrakesecrethere
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
当我重新启动服务器并访问任何页面时,在我的浏览器中出现“内部服务器错误”。
在我的日志文件中,我看到:
$ rails s
=> Booting Thin
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
Unexpected error while processing request: (<unknown>): found character that cannot start any token while scanning for the next token at line 14 column 1
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:153:in `parse'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:129:in `load'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:15:in `load_with_options'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:313:in `secrets'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:439:in `validate_secret_key_config!'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:195:in `env_config'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/engine.rb:510:in `call'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:144:in `call'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/server.rb:69:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:81:in `block in server'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `tap'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `server'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Unexpected error while processing request: (<unknown>): found character that cannot start any token while scanning for the next token at line 14 column 1
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:153:in `parse'
/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:129:in `load'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:15:in `load_with_options'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:313:in `secrets'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:439:in `validate_secret_key_config!'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:195:in `env_config'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/engine.rb:510:in `call'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/application.rb:144:in `call'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:86:in `block in pre_process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:84:in `catch'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pre_process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:53:in `process'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/connection.rb:39:in `receive_data'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/thin-1.6.2/lib/thin/server.rb:162:in `start'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
/.rvm/gems/ruby-2.0.0-p353@global/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/server.rb:69:in `start'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:81:in `block in server'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `tap'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `server'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/.rvm/gems/ruby-2.0.0-p353@my_project/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
关于可能导致这种情况的任何想法?
我尝试了 secrets.yml 文件的多次迭代,甚至将secret_key_base
单引号括起来'somelongasskeyhere'
,但那不起作用。
更新 1
所以看起来问题可能在于 finnicky YAML 的程度。我认为这与我输入的间距和制表符有关,但我似乎无法让它完美。现在我在该行的不同位置遇到另一个错误。
在重新做一些空格以仅使用空格键 4 次之后,与设置为 4 个空格的制表符相比,我现在得到了一个不同的错误:
Unexpected error while processing request: (<unknown>): found a tab character that violate intendation while scanning a plain scalar at line 13 column 3
其中引用了这一行:
development:
secret_key_base:'86bc42f97803818b48ff88ef15d9d4df6b6b4e4e723c119967a29751de33b5687af3a57542b4a8364cb3d6b51a872ad1188b9de6f0faab578272451aa798956c'
更新 2
这肯定与我的间距有关,因为一旦我复制并粘贴了这个文件 - https://github.com/RailsApps/rails-devise/blob/master/config/secrets.yml - 到我的并替换了key_base和我的一样,一切都很好。