我试图在heroku上设置我的应用程序。在此之前,我可以输入rails s
来启动服务器,一切都完美无瑕。
然后(可能与我的实际问题无关),我将config.secret_key_base = ENV["SECRET_KEY_BASE"]
添加到我的config/evironments/production.rb
文件并将其推送到github,然后将其推送到heroku。 heroku上的应用程序可以运行。
之后,每当我输入rails s时,都会发生这种情况:
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:这是我的宝石文件:
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:@Rewritten:你的意思是这样的?如果是这样,我仍然有同样的错误
development:
<<: *default
database: philosophica_development
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
username: name
password: password
答案 0 :(得分:2)
您的default
块似乎在文件中已关闭。 YAML无法查找前向引用,因此&default
标记必须位于其对应的<<: *default
插入点之前。
# not working
development:
<<: *default
default: &default
adapter: postgresql
而不是
# working
default: &default
adapter: postgresql
development:
<<: *default
答案 1 :(得分:2)
检查语法错误是否在项目中的其他引用的yml文件中(例如secrets.yml)。
似乎secrets.yml中的错误在database.yml中被报告为错误。
答案 2 :(得分:0)
请检查此空行中是否没有像'tab'这样的空白字符,因为:
请注意,YAML必须始终使用空格缩进。 不允许使用标签。
答案 3 :(得分:0)
尝试更改密码,也许您正在使用一些影响解析的无效字符