Postgres gem 未在初始 Rails 4 应用程序部署时加载

Postgres gem not loaded on initial Rails 4 app deployment

我现在在我的本地机器和 heroku 上安装了我的 Rails 4 应用程序 运行。现在我尝试设置一个 ubutunu 14 服务器。对于部署,我使用的是 capistrano,并且我的本地计算机和服务器之间的连接已经设置。目前我正在尝试使用此命令进行初始部署:

cap production deploy:initial

我在某个时候遇到以下错误:

Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on MYIP
DEBUG Command: cd /home/deploy/apps/savoir/releases/20160209113448 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG        rake aborted!
DEBUG        Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

我的 gemfile 如下所示:

source 'http://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# 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', '~> 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

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]

gem 'bootstrap-sass', '~> 3.3.5.1'
gem 'autoprefixer-rails'
gem 'bootstrap-sass-extras'
gem 'bootstrap-daterangepicker-rails'
gem 'bootstrap-datepicker-rails'

gem 'simple_form'
gem 'nested_form'

gem 'ckeditor'
gem 'coffee-script-source', '1.8.0'
gem 'carrierwave', github:'carrierwaveuploader/carrierwave'
gem 'carrierwave-crop'
gem 'rmagick'
gem 'mini_magick'

gem 'momentjs-rails'
gem 'gon'

gem 'jquery-ui-rails'
gem 'jquery-fileupload-rails'
gem 'jquery-turbolinks'
gem 'jquery-validation-rails'

gem 'devise'

gem 'ransack'
gem 'will_paginate'

gem 'rails_12factor'
gem 'pg', '~> 0.18.3'   

gem 'geocoder'
gem 'gmaps4rails'
gem 'underscore-rails'

group :development do
    gem 'capistrano',         require: false
    gem 'capistrano-rvm',     require: false
    gem 'capistrano-rails',   require: false
    gem 'capistrano-bundler', require: false
    gem 'capistrano3-puma',   require: false
end

gem 'puma'

还有我的database.yml:

development:
  adapter: postgresql
  database: savoir_development
  pool: 5
  username: postgres
  password: root

test:
  adapter: postgresql
  database: savoir_test
  pool: 5
  timeout: 5000
  username: postgres
  password: root

production:
  adapter: postgresql
  database: deploy
  pool: 5
  timeout: 5000
  username: USER
  password: PASSWORD

据我所知,gemfile 和 database.yml 应该没问题。谁能找到我犯的错误?我发现了其他一些与此主题相关的话题,但它们对我的情况没有帮助。

好的,我找到了解决方案。

由于我在本地机器上使用 windows,rails 使用了这个版本的 pg:

//Gemlock.lock
pg (0.18.4-x86-mingw32)

改成

//Gemlock.lock
pg (0.18.4)

并将其推送到 git 解决了我的问题。