有一个工作的rails应用程序并得到一个奇怪的错误 - rails甚至指定mysql适配器使用postgresql。一切都工作得很好,直到我在另一个使用postgresql的项目上工作。
但是,这仍然没有任何意义。我已经在这几个小时了。也许我只是失明,我非常感谢你的帮助。
本地测试的错误信息:
bash-3.2$ rails s
=> Booting WEBrick
=> Rails 4.0.3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile. (Gem::LoadError)
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:32:in `spec'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_handling.rb:39:in `establish_connection'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/railtie.rb:176:in `block (2 levels) in <class:Railtie>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `each'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/railtie.rb:174:in `block in <class:Railtie>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `run'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /Users/mg/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/application.rb:215:in `initialize!'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/mg/Dropbox/delightotet/delighto/config/environment.rb:16:in `<top (required)>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
from /Users/mg/Dropbox/delightotet/delighto/config.ru:3:in `block in <main>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/mg/Dropbox/delightotet/delighto/config.ru:in `new'
from /Users/mg/Dropbox/delightotet/delighto/config.ru:in `<main>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/commands/server.rb:48:in `app'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/commands/server.rb:75:in `start'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/commands.rb:76:in `block in <top (required)>'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/commands.rb:71:in `tap'
from /Users/mg/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
的database.yml
development:
adapter: mysql2
database: xxx
user: xxx
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
database: xxx
user: xxx
password:
production:
adapter: mysql2
database: xxx
user: xxx
password: xxx
我的Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'
gem 'mysql2'
gem 'sprockets', '2.11.0'
gem 'mail_form'
# Use SCSS for stylesheets
gem 'sass-rails'
# DROPBOX
gem 'dropbox-sdk'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'
#mailchimp
gem 'gibbon'
gem 'mandrill-api'
gem 'net-ssh', '~>2.7.0'
#devise auth
gem 'devise'
# SUPPORT PROCESSES
gem "zendesk_api"
# AFTER SALES PROCESSES
# SHIPPING SOLUTIONS
gem 'dhl-intraship'
# GENERATE PDF INVOICE
gem 'spree_print_invoice' , :git => 'https://github.com/mgreschke/spree_print_invoice.git', branch:'2-2-stable'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'gritter'
gem 'friendly_id'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
#password encryption
gem "bcrypt-ruby", :require => "bcrypt"
gem 'money', '6.0.1'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
gem "capistrano", "2.14.2", group: :development
gem "mime-types", "1.25"
gem "rake", "10.3.1"
#meta tags
gem 'meta-tags'
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'spree', '2.2.1'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-2-stable'
gem 'spree_i18n', :github => 'spree/spree_i18n', :branch => '2-2-stable'
答案 0 :(得分:3)
如果你有一个名为DATABASE_URL
的环境变量,那么rails将使用它。
这在rails guides中有记录,它特别声明rails会尝试将database.yml与环境变量合并,环境变量优先。
我认为,作为您提到的其他一个postgres项目的一部分,您已设置此环境变量。如果在shell提示符下运行env
,则应该会看到一个环境变量列表。如果DATABASE_URL
存在并且在您打开/关闭终端窗口后仍然存在,那么您可能正在其中一个shell启动文件中设置它(例如对于bash try .bashrc,.bash_profile)