簡體   English   中英

本地啟動服務器時出錯:“找不到預期的':'”,Ruby on Rails

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

我試圖在heroku上設置我的應用程序。 在此之前,我可以鍵入rails s來啟動服務器,然后一切順利。

然后(可能與我的實際問題無關),我將config.secret_key_base = ENV["SECRET_KEY_BASE"]config/evironments/production.rb文件中,並將其推到github,然后推到了heroku。 heroku上的應用程序有效。

之后,每當我輸入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>'

我注意到了這一點:

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)

這是我的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

它在第24行提到一個錯誤,但第24行為空。 在這一點上,我一無所知。 有沒有人建議? 提前致謝!

編輯1:我的默認值似乎是第一位,這里是我的database.yml:

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



development:
  <<: *default
  database: philosophica_development

編輯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

我的config/environment.rb看起來像這樣:

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

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

也許這是有幫助的

編輯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

編輯4:@重寫:您的意思是這樣嗎? 如果是這樣,我仍然有相同的錯誤

development:
  <<: *default
  database: philosophica_development

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

似乎您的default阻止已在文件中。 YAML無法查找前向引用,因此&default標記必須位於其對應的<<: *default插入點之前。

# not working
development:
  <<: *default

default: &default
  adapter: postgresql

代替

# working
default: &default
  adapter: postgresql

development:
  <<: *default

檢查語法錯誤是否在項目中其他引用的yml文件中(例如secrets.yml)。

似乎secrets.yml中的錯誤被報告為database.yml中的錯誤。

請檢查此空行中是否沒有空白字符(如“ tab”),原因是:

請注意,YAML必須始終使用空格縮進。 不允許使用制表符

嘗試更改密碼,也許您使用的某些無效字符會影響解析

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM