简体   繁体   English

本地启动服务器时出错:“找不到预期的':'”,Ruby on Rails

[英]Error when starting server locally: “could not find expected ':'” , Ruby on Rails

I was trying to set up my app on heroku. 我试图在heroku上设置我的应用程序。 Before that, I could type rails s to start the server and everything went flawless. 在此之前,我可以键入rails s来启动服务器,然后一切顺利。

Then (maybe unrelated to my actual problem), I added config.secret_key_base = ENV["SECRET_KEY_BASE"] to my config/evironments/production.rb file and pushed it to github and after that, to heroku. 然后(可能与我的实际问题无关),我将config.secret_key_base = ENV["SECRET_KEY_BASE"]config/evironments/production.rb文件中,并将其推到github,然后推到了heroku。 The app on heroku works. heroku上的应用程序有效。

After that, whenever I type rails s, this happens: 之后,每当我输入rails时,就会发生这种情况:

mycomp:~/workspace/philosophica$ rails s
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/application/configuration.rb:115:in `rescue in database_configuration': YAML syntax error occurred while parsing /home/sandro/workspace/philosophica/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): could not find expected ':' while scanning a simple key at line 24 column 1 (RuntimeError)
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/application/configuration.rb:98:in `database_configuration'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5/lib/active_record/railtie.rb:117:in `block (2 levels) in <class:Railtie>'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `each'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
        from /home/sandro/workspace/philosophica/config/environment.rb:5:in `<top (required)>'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
        from /home/sandro/workspace/philosophica/config.ru:3:in `block in <main>'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
        from /home/sandro/workspace/philosophica/config.ru:in `new'
        from /home/sandro/workspace/philosophica/config.ru:in `<main>'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
        from /home/sandro/.gem/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
        from /home/sandro/workspace/philosophica/bin/rails:9:in `require'
        from /home/sandro/workspace/philosophica/bin/rails:9:in `<top (required)>'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
        from /home/sandro/.gem/ruby/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/sandro/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/sandro/workspace/philosophica/bin/spring:13:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

I noticed this: 我注意到了这一点:

YAML syntax error occurred while parsing /home/sandro/workspace/philosophica/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): could not find expected ':' while scanning a simple key at line 24 column 1 (RuntimeError)

Here is how my database.yml looks like: 这是我的database.yml的样子:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: a_number
  host: localhost    #line 21
  username: name     #line 22
  password: password #line 23
                     #line 24

It mentions an error at line 24, but line 24 is empty. 它在第24行提到一个错误,但第24行为空。 At this point, I'm clueless. 在这一点上,我一无所知。 Has anyone any advises? 有没有人建议? Thanks in advance! 提前致谢!

Edit 1: My default seems to come first, here my database.yml: 编辑1:我的默认值似乎是第一位,这里是我的database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  host: localhost
  username: name
  password: pasword



development:
  <<: *default
  database: philosophica_development

Edit 2: When I type in rake routes this happens: 编辑2:当我输入rake routes时,会发生这种情况:

rake aborted!
YAML syntax error occurred while parsing /home/sandro/workspace/philosophica/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): could not find expected ':' while scanning a simple key at line 24 column 1
/home/sandro/workspace/philosophica/config/environment.rb:5:in `<top (required)>'
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 24 column 1
(erb):87:in `<main>'
/home/sandro/workspace/philosophica/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment

My config/environment.rb looks like this: 我的config/environment.rb看起来像这样:

# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!  #line 5

Maybe this is helpful 也许这是有帮助的

Edit 3: Here is my gemfile: 编辑3:这是我的gemfile:

source 'https://rubygems.org'

ruby File.read('.ruby-version').strip

gem 'devise'
gem 'figaro'
gem 'pg_search'

gem 'bootstrap3-datetimepicker-rails'
gem 'momentjs-rails'
gem 'bootstrap-datepicker-rails'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use postgresql as the database for Active Record
gem 'mailgun-ruby', '~>1.0.2', require: 'mailgun'
gem 'delayed_job_active_record'
gem 'tinymce-rails'
gem 'pg', '~> 0.15'

group :production do
  gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'acts-as-taggable-on'
gem 'rake', '~> 11.1.2'
gem 'simple_form'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'gon'
gem 'sprockets'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

Edit 4: @Rewritten: You mean like this? 编辑4:@重写:您的意思是这样吗? If so, I still have the same error 如果是这样,我仍然有相同的错误

development:
  <<: *default
  database: philosophica_development

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  host: localhost
  username: name
  password: password

It seems that your default block is down in the file. 似乎您的default阻止已在文件中。 YAML is not able to look for forward references, so the &default marker MUST come before its corresponding <<: *default insertion point(s). YAML无法查找前向引用,因此&default标记必须位于其对应的<<: *default插入点之前。

# not working
development:
  <<: *default

default: &default
  adapter: postgresql

instead of 代替

# working
default: &default
  adapter: postgresql

development:
  <<: *default

Check if the syntax error is in an other referenced yml file in the project (eg secrets.yml). 检查语法错误是否在项目中其他引用的yml文件中(例如secrets.yml)。

It seems that errors in secrets.yml are reported as errors in database.yml. 似乎secrets.yml中的错误被报告为database.yml中的错误。

Please check if in this empty line there are no blank characters like 'tab' because: 请检查此空行中是否没有空白字符(如“ tab”),原因是:

Please note that YAML must be consistently indented using spaces. 请注意,YAML必须始终使用空格缩进。 Tabs are not allowed . 不允许使用制表符

尝试更改密码,也许您使用的某些无效字符会影响解析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM